Playing a Video in Videoview in Android

Playing a video in VideoView in Android

My guess is that your video is incompatible with Android. Try it with a different video. This one definitely works used to work with Android (but does not on newer devices, for some reason). If that video works, and yours does not, then your video is not compatible with Android.

As others have indicated, please test this on a device. Video playback on the emulator requires too much power.

UPDATE 2020-02-18: https://law.duke.edu/cspd/contest/videos/Framed-Contest_Documentaries-and-You.mp4 is an MP4 of the same content, but I have no idea if it is the same actual MP4 as I previously linked to.

How to play .mp4 video in videoview in android?

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();
}
});

Play video from url in VideoView [Android]

Try this code.. This code works perfectly for me..

VideoView videoView = findViewById(R.id.videoView);
videoView.setVideoPath("http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4");
videoView.start();

Playing video in videoview android

I found the solution. Actually the problem was in encoding of video. I was using gingerbread emulator to test application and the video was in mp4 h.264. But it seems gingerbread is capable in playing mp4 or 3gpp h.263 only in default.

Can't play this video Error using URL with VideoView and Mediacontroller

So I've ended up fixing it myself. The problem wasn't in the code, for anyone wondering I've ended up using this simple format:

    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video = (VideoView) findViewById(R.id.video);

Uri uri = Uri.parse("http://techslides.com/demos/sample-videos/small.mp4");
video.setMediaController(new MediaController(this));
video.setVideoURI(uri);
video.requestFocus();
video.start();

}

The problem was the AVD itself. I had a Pixel 1 running Android 9, and that for some reason didn't work. I've installed a Nexus 5 with Oreo and it works flawlessly.

Can't play video in VideoView - why?


it says that this error occurs due to issues like incorrect URL or
incompatible format but the video is .mp4 with the H264 codec.

=> Reason being is VideoView is not that much powerful and extensible, in terms of codecs and other features.

Rather I would suggest going with ExoPlayer library.

There are multiple things why VideoView is failed to play video, one of the reasons being is when you record using other devices like iPhone, Camcorder, etc. They have a different format of video which might not be supported, also codec might not be supported. In this case, when we are developing solutions and having android/iPhone/TV or other mediums involved, we implement a code over backend for maintaining a single codec and that's how we maintain the compatibility with all the devices.



Related Topics



Leave a reply



Submit