45

I am working on a video player application, I want to play .mp4 video in the native video view. I am not able to play video using a URL. I am getting the error "Sorry this video cannot be played" and I am also not able to play downloaded video in the native video view either.

My code for playing video in the video view:

String mUrl = "http://www.servername.com/projects/projectname/videos/1361439400.mp4";

VideoView mVideoView  = (VideoView)findViewById(R.id.videoview)
videoMediaController = new MediaController(this);
mVideoView.setVideoPath(mUrl);
videoMediaController.setMediaPlayer(mVideoView);
mVideoView.setMediaController(videoMediaController);
mVideoView.requestFocus();
mVideoView.start();
zcoop98
  • 2,590
  • 1
  • 18
  • 31
Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
  • It's likely that that particular mp4 encoding is not supported. I answered in a seperate answer. To test you can try another mp4, for example this one works for me: http://archive.org/download/Pbtestfilemp4videotestmp4/video_test.mp4 – Ken Wolf Jul 01 '13 at 08:16
  • 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

6 Answers6

41

Finally it works for me.

private VideoView videoView;

videoView = (VideoView) findViewById(R.id.videoView);

Uri video = Uri.parse("http://www.servername.com/projects/projectname/videos/1361439400.mp4");
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  @Override       
  public void onPrepared(MediaPlayer mp) {
       mp.setLooping(true);
       videoView.start();
    }
});
avs
  • 122
  • 1
  • 12
Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
31

MP4 is just a container - the video and audio stream inside it will both be encoded in different formats.

Android natively only supports certain types of formats. This is the list here.

Make sure the video and audio encoding type is supported. Just because it says "mp4" doesn't automatically mean it should be playable.

gprathour
  • 14,813
  • 5
  • 66
  • 90
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
23

Use Like this:

Uri uri = Uri.parse(URL); //Declare your url here.

VideoView mVideoView  = (VideoView)findViewById(R.id.videoview)
mVideoView.setMediaController(new MediaController(this));       
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();

Another Method:

  String LINK = "type_here_the_link";
  VideoView mVideoView  = (VideoView) findViewById(R.id.videoview);
  MediaController mc = new MediaController(this);
  mc.setAnchorView(videoView);
  mc.setMediaPlayer(videoView);
  Uri video = Uri.parse(LINK);
  mVideoView.setMediaController(mc);
  mVideoView.setVideoURI(video);
  mVideoView.start();

If you are getting this error Couldn't open file on client side, trying server side Error in Android. and also Refer this. Hope this will give you some solution.

Community
  • 1
  • 1
Nirmal
  • 2,340
  • 21
  • 43
  • 1
    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
  • 15
    Error msg "Can't Play this video" – Prasad Sep 29 '14 at 05:04
6

Check the format of the video you are rendering. Rendering of mp4 format started from API level 11 and the format must be mp4(H.264)

I encountered the same problem, I had to convert my video to many formats before I hit the format: Use total video converter to convert the video to mp4. It works like a charm.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Michael
  • 588
  • 11
  • 19
  • i encounter the same problem i have to convert my video to many format before i hit the format: use total video converter to convert the video to mp4. trust me it works like charm – Michael Nov 07 '15 at 20:23
  • according to the android documentary mp4 is only supported from API Level 11 (Gingerbread) – Michael Nov 07 '15 at 20:25
  • Next time please edit you answer when you are enhancing it, rather than adding comments. I have shifted one of the comments in for you. – Rohit Gupta Nov 07 '15 at 21:06
3

I'm not sure that is the problem but what worked for me is calling mVideoView.start(); inside the mVideoView.setOnPreparedListener event callback.

For example:

Uri uriVideo = Uri.parse(<your link here>);

MediaController mediaController = new MediaController(mContext);
mediaController.setAnchorView(mVideoView);
mVideoView.setMediaController(mediaController);
mVideoView.setVideoURI(uriVideo);
mVideoView.requestFocus();

mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
     @Override
     public void onPrepared(MediaPlayer mp)
     {
          mVideoView.start();
     }
});
enadun
  • 3,107
  • 3
  • 31
  • 34
EZDsIt
  • 921
  • 1
  • 9
  • 14
1

In Kotlin you can do as

 val videoView = findViewById<VideoView>(R.id.videoView)

       // If url is from raw
   /* val url = "android.resource://" + packageName
        .toString() + "/" + R.raw.video*/

    // If url is from network
    val url = "http://www.servername.com/projects/projectname/videos/1361439400.mp4"

    val video =
        Uri.parse(url)
    videoView.setVideoURI(video)
    videoView.setOnPreparedListener{
        videoView.start()
    }
Alok Mishra
  • 1,904
  • 1
  • 17
  • 18