How can I play MP4 video by direct link in Android Android players?

I am creating an Android application in which I need to play mp4 video in my own default Android video player via a direct download link.

To open the player for Android, I use 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 a direct downloadable link for mp4 video. This code opens the video player, but the video does not load into the video player

I also used this URL

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

This URL contains the html5 video player, but the video is not uploaded to the Android Android player.

But when I use a 3GP video link like

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

Then it works.

Please, help.

+5
source share
1 answer

Try what I did

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

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


Update

Firstly, videos can have problems, as not all videos are safe for streaming .

Secondly, not all devices can have actions configured 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 startActivity() ActivityNotFoundException that you get.

You need to check the Android Encoding Recommendation . Make sure your video is encoded with supported code and your video matches the permissions. After the video was correctly encoded, the work with the stream worked.

Also, if you have not noticed yet, as a rule, the emulator does not play them, and you will need to test on a real device.

+2
source

Source: https://habr.com/ru/post/1203763/


All Articles