43

I am beginner in android development and try to play video from link. But it's giving error "sorry,we can't play this video". I tried so many links but for all links its show same error.

My code is the following

public class VideoDemo extends Activity {

        private static final String path ="http://demo.digi-corp.com/S2LWebservice/Resources/SampleVideo.mp4";
 private VideoView video;
 private MediaController ctlr;
 @Override
 public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            getWindow().setFormat(PixelFormat.TRANSLUCENT);
            setContentView(R.layout.videoview);

            video = (VideoView) findViewById(R.id.video);
            video.setVideoPath(path);

            ctlr = new MediaController(this);
            ctlr.setMediaPlayer(video);
            video.setMediaController(ctlr);
            video.requestFocus();
     }
}

Logcat shows following error message:

04-12 15:04:54.245: ERROR/PlayerDriver(554): HandleErrorEvent: PVMFErrTimeout
Dhasneem
  • 4,037
  • 4
  • 33
  • 47
priyanka
  • 431
  • 1
  • 4
  • 3

9 Answers9

47

It has something to do with your link and content. Try the following two links:

    String path="http://www.ted.com/talks/download/video/8584/talk/761";
    String path1="http://commonsware.com/misc/test2.3gp";

    Uri uri=Uri.parse(path1);

    VideoView video=(VideoView)findViewById(R.id.VideoView01);
    video.setVideoURI(uri);
    video.start();

Start with "path1", it is a small light weight video stream and then try the "path", it is a higher resolution than "path1", a perfect high resolution for the mobile phone.

Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56
  • 3
    well, web master at www.ted.com will be pissed at my answer for using their url which all the all the android devs here testing it against! Please find your own video url :) – Win Myo Htet Jan 21 '14 at 19:31
  • 2
    i do the same but still i cant play .mp4 video 08-12 14:37:30.599: D/MediaPlayer(23633): Couldn't open file on client side, trying server side 08-12 14:37:33.095: E/MediaPlayer(23633): error (1, -2147483648) 08-12 14:37:33.096: E/MediaPlayer(23633): Error (1,-2147483648) 08-12 14:37:33.096: D/VideoView(23633): Error: 1,-2147483648 got this error – Vaishali Sutariya Aug 12 '14 at 09:08
  • 1
    To everyone who is getting a 404 error - It is because That TED Talk no longer exists. Find a new video URL to try instead. – Mr. Arbitrary May 22 '19 at 16:50
  • Couldn't open http://xxxx.com/... java.io.FileNotFoundException: No content provider: http://xxxx.com/test.mp4 – Prashant Aug 09 '20 at 01:52
8

Try this:

String LINK = "type_here_the_link";
setContentView(R.layout.mediaplayer);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
gtsiolis
  • 136
  • 1
  • 6
6
pDialog = new ProgressDialog(this);

    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(mVideoView);      

        Uri videoUri = Uri.parse(videoUrl);
        mVideoView.setMediaController(mediacontroller);
        mVideoView.setVideoURI(videoUri);

    } catch (Exception e) {

        e.printStackTrace();
    }

    mVideoView.requestFocus();
    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            mVideoView.start();
        }
    });
    mVideoView.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            if (pDialog.isShowing()) {
                pDialog.dismiss();
            }
            finish();               
        }
    });
Vaishali Sutariya
  • 5,093
  • 30
  • 32
5

You can do it using FullscreenVideoView class. Its a small library project. It's video progress dialog is build in. it's gradle is :

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'

your VideoView xml is like this

<com.github.rtoshiro.view.video.FullscreenVideoLayout
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

In your activity , initialize it using this way:

    FullscreenVideoLayout videoLayout;

videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
        videoLayout.setActivity(this);

        Uri videoUri = Uri.parse("YOUR_VIDEO_URL");
        try {
            videoLayout.setVideoURI(videoUri);

        } catch (IOException e) {
            e.printStackTrace();
        }

If want to know more then visit here, where the code snippets above also come from. Credits to Toshiro

Edit: gradle path has been updated. compile it now

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2'
blackgreen
  • 34,072
  • 23
  • 111
  • 129
Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87
  • @Sajedul library is good but after play for some seconds it will stop playing. MediaPlayer: error(1, -1004) will print in logcat. why is it so?I am trying to play http://sharemyideo.esy.es/upload/videos/922a4a6a4e370acb94c84fe0039c66f2.mp4 this video. – Nitish Patel Nov 06 '16 at 13:18
  • they added new release in their stable channel. Can you update it's gradle path compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2' Hope this will solve your problem – Md. Sajedul Karim Nov 07 '16 at 06:09
  • will this support both **Youtube** and **Vimeo** URLs? – Shihas Jul 20 '17 at 05:12
4

Try Exoplayer2

https://github.com/google/ExoPlayer

It is highly customisable

    private void initializePlayer() {
         player = ExoPlayerFactory.newSimpleInstance(
             new DefaultRenderersFactory(this),
             new DefaultTrackSelector(), new DefaultLoadControl());

         playerView.setPlayer(player);

         player.setPlayWhenReady(playWhenReady);
         player.seekTo(currentWindow, playbackPosition);

Uri uri = Uri.parse(getString(R.string.media_url_mp3));
     MediaSource mediaSource = buildMediaSource(uri);
     player.prepare(mediaSource, true, false);
    }

private MediaSource buildMediaSource(Uri uri) {
  return new ExtractorMediaSource.Factory(
      new DefaultHttpDataSourceFactory("exoplayer-codelab")).
      createMediaSource(uri);
}

@Override
public void onStart() {
 super.onStart();
 if (Util.SDK_INT > 23) {
   initializePlayer();
 }
}

Check this url for more details

https://codelabs.developers.google.com/codelabs/exoplayer-intro/#2

BraveEvidence
  • 53
  • 11
  • 45
  • 119
1

please check this link : http://developer.android.com/guide/appendix/media-formats.html

videoview can't support some codec .

i suggested you to use mediaplayer , when get "sorry , can't play video"

Adnan Abdollah Zaki
  • 4,328
  • 6
  • 52
  • 58
1

I also got stuck with this issue. I got correct response from server, but couldn`t play video. After long time I found a solution here. Maybe, in future this link will be invalid. So, here is my correct code

    Uri video = Uri.parse("Your link should be in this place "); 
    mVideoView.setVideoURI(video); 

   mVideoView.setZOrderOnTop(true); //Very important line, add it to Your code
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
        @Override 
        public void onPrepared(MediaPlayer mediaPlayer) {
  // here write another part of code, which provides starting the video
  }}
Roman Soviak
  • 791
  • 2
  • 9
  • 30
0

Check this UniversalVideoView library its simple and straight forward with controller as well.

Here is the code to play the video
Add this dependancyy in build.gradle

 implementation 'com.linsea:universalvideoview:1.1.0@aar'

Java Code

        UniversalVideoView mVideoView = findViewById(R.id.videoView);
        Uri uri=Uri.parse("https://firebasestorage.googleapis.com/v0/b/contactform-d9534.appspot.com/o/Vexento%20-%20Masked%20Heroes.mp4?alt=media&token=74c2e448-5b1b-47b7-b761-66409bcfbf56");
        mVideoView.setVideoURI(uri);
        UniversalMediaController mMediaController = findViewById(R.id.media_controller);
        mVideoView.setMediaController(mMediaController);
        mVideoView.start();   

Xml Code

<FrameLayout
            android:id="@+id/video_layout"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/black">

            <com.universalvideoview.UniversalVideoView
                android:id="@+id/videoView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                app:uvv_autoRotation="true"
                app:uvv_fitXY="false" />

            <com.universalvideoview.UniversalMediaController
                android:id="@+id/media_controller"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                app:uvv_scalable="true" />

        </FrameLayout>
Kunchok Tashi
  • 2,413
  • 1
  • 22
  • 30
-1

Check whether your phone supports the video format or not.Even I had the problem when playing a 3gp file but it played a mp4 file perfectly.

p.mathew13
  • 920
  • 8
  • 16