如何在Android中使用意向播放视频? [英] 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.
我用这code播放视频:
I am using this code to play video:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");
view.getContext().startActivity(intent);
然而,在某些情况下,这code没有在多台设备的工作,我的应用程序的一些用户说,它的力量关闭时,他们preSS任何一个环节的整个应用程序。其实,我试图在我的G1和Droid X的,它的工作完全正常。
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.
有什么我做错了什么?请帮帮我,我真的AP preciate了很多。
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.
其次,并非所有的设备可能会设置为支持 ACTION_VIEW
在视频/ MP4
的流式传输文件活动。您应该使用 PackageManager
和 queryIntentActivities()
确认是否 startActivity()
通话将找到一个匹配,或处理 ActivityNotFoundException
,你得到的。
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.
这篇关于如何在Android中使用意向播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!