How to play .mp4 video in videoview in android?
Solution 1
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();
}
});
Solution 2
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.
Solution 3
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.
Solution 4
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.
Solution 5
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();
}
});
Related videos on Youtube
Comments
-
Hiren Patel almost 2 years
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();
-
Ken Wolf almost 11 yearsIt'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: archive.org/download/Pbtestfilemp4videotestmp4/video_test.mp4
-
Vaishali Sutariya almost 10 yearsi 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 almost 10 yearsi 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
-
Prasad over 9 yearsError msg "Can't Play this video"
-
Michael over 8 yearsi 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 over 8 yearsaccording to the android documentary mp4 is only supported from API Level 11 (Gingerbread)
-
Rohit Gupta over 8 yearsNext time please edit you answer when you are enhancing it, rather than adding comments. I have shifted one of the comments in for you.
-
Arpit Patel over 7 yearswhat is mp in above snippet??
-
Hiren Patel over 7 yearsIts an object of media player.
-
Muhammed Refaat over 6 yearsso, how to know/set video encoding technique
-
sejn about 3 years@HirenPatel But initially It shows a black screen.