播放视频文件的最佳方式?
我有一个视频文件的 URL,我需要使用手机的本机视频播放器来播放该文件。
我认为使用 Intent.ACTION_VIEW
并将 URI 设置为 Intent 数据,我能够在除 HTC Hero 之外的 G1 上实现上述目标。对于 Hero,我必须在 Intent 中显式设置类名称才能启动默认视频播放器: intent.setClassName("com.htc.album","com.htc.album.ViewVideo");< /code>
但是,我对这种方法不太满意,因为它可能会在其他 Android 设备上崩溃。请提供以下建议:
1. 无论手机如何,通过 Intent 播放此视频 URL 的最佳方式是什么?
2. 如何在 Intent 中针对手机有条件地设置 ClassName?
注意:目前我们无法为我们的应用程序编写独立的视频播放器。
谢谢!
I have a URL for a video file which I need to play using the native Video-player of the handset.
I figured using Intent.ACTION_VIEW
and setting the URI as Intent data, I am able to achieve the aforementioned on G1 except HTC hero. In case of Hero, I have to explicitly set the class Name in the Intent to start the default Video Player: intent.setClassName("com.htc.album","com.htc.album.ViewVideo");
However, I am not comfortable with this approach as it might break on other Android devices. Please advice on :
1. What would be the best way to play this video url via Intent, irrespective of the handset?
2. How to conditionally setClassName in Intent, specific to a Handset?
Note: Writing a standalone Video Player for our app is NOT an option we can afford at the moment.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,视频播放器是 不是 SDK 的一部分,并且依赖它是一个很大的错误,正如您已经发现的那样。
其次,创建一个简单的视频播放器大约需要 40 行代码,并且您已经花费了更多的时间来尝试避免编写这 40 行代码,而这些代码本来只是在第一时间编写的。
First, the video player is not part of the SDK, and relying upon it is a big mistake, as you have already discovered.
Second, creating a simple video player takes about 40 lines of code, and you have already spent more time trying to avoid writing those 40 lines of code that it would have taken just to write the lines in the first place.