How to play video using Intent in Android?
Few weeks ago I decided to make an app, this app contained just video links that allows the users to watch clips whenever they click any button link.
I am using this code to play video:
Intent intent = new Intent(Intent.ACTION_VIEW);
int开发者_开发问答ent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");
view.getContext().startActivity(intent);
However, in some cases this code doesn't work in several devices, some users of my app said it force closes the entire app whenever they press any link. I actually tried it in my G1 and Droid X, it worked perfectly fine.
Is there anything I am doing wrong? Please help me, I would really appreciate it a lot.
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.
I wrote this :
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");
Then i add the permission : android.permission.WRITE_EXTERNAL_STORAG
E , to my manifest.
精彩评论