Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I play MP4 video through a direct link in Android video player?

I am making an Android application in which i need to play mp4 video in the android default native video player through a direct downloadable link.

To open the Android video player I am using the following code

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://b.revvolution.com/video/albums-3ry/newshare-der-34972.mp4?download=1"));

intent.setDataAndType(Uri.parse("http://b.revvolution.com/video/albums-3ry/newshare-der-34972.mp4?download=1"), "video/*");

startActivity(intent);

Here the URL is direct downloadable link for the mp4 video. This code opens the video player but video is not loaded in the video player

I have also used this URL

http://b.revvolution.com/video/albums-3ry/newshare-der-34972.mp4

This URL contains a html5 video player but the video is not loaded in Android video player

But when i use a link of 3GP video like

http://www.androidbegin.com/tutorial/AndroidCommercial.3gp

Then it works.

Please help.

like image 869
Manish Agrawal Avatar asked Oct 31 '22 16:10

Manish Agrawal


1 Answers

Try the way I did

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");

Then add the permission : android.permission.WRITE_EXTERNAL_STORAGE , to manifest.


update

First, the video may have issues, as not all videos are safe for streaming.

Second, not all devices may have activities set up to support ACTION_VIEW on video/mp4 files that are streamed. You should use PackageManager and queryIntentActivities() to confirm whether the startActivity() call will find a match, or handle the ActivityNotFoundException that you get.

You need to check the Android Video Encoding Recommandations . Make sure that your video is encoded with the supported code, and your video respects the resolutions.After the video were properly encoded the streamming worked.

Also if you didn't noticed yet, usually the emulator does not play them, and you'll have to test on a real device.

like image 176
Maveňツ Avatar answered Nov 15 '22 05:11

Maveňツ