播放视频的Android意图? [英] Android intent for playing video?

查看:24
本文介绍了播放视频的Android意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过启动意图在 Android 上播放视频.我使用的代码是:

I'm trying to play video's on Android, by launching an intent. The code I'm using is:

tostart = new Intent(Intent.ACTION_VIEW);
tostart.setDataAndType(Uri.parse(movieurl), "video/*");
startActivity(tostart); 

这适用于大多数手机,但不适用于 HTC Hero.它似乎加载了一些不同的视频播放器.这确实会播放第一个扔给它的视频.但是,之后的每个视频都没有响应.(它保持在某个循环中).

This works on most phones, but not on the HTC Hero. It seems to load a bit different video player. This does play the first video thrown at it. However, every video after that it doesn't respond. (it keeps in some loop).

如果我添加一个明确的

tostart.setClassName("com.htc.album","com.htc.album.ViewVideo");

(在 startactivity 之前)它确实适用于 HTC Hero.但是,由于这是 HTC 特定调用,我无法在其他手机(例如 G1)上运行此代码.在 G1 上,这有效:

(before the startactivity) it does work on the HTC Hero. However, since this is a HTC specific call, I can't run this code on other phones (such as the G1). On the G1, this works:

tostart.setClassName("com.android.camera","com.android.camera.MovieView"); //g1 version

但英雄没有这种意图.有人知道所有 Android 设备都应该支持的意图/类名列表吗?还是一个特定的启动视频?谢谢!

But this intent is missing from the hero. Does anybody know a list of intents/classnames that should be supported by all Android devices? Or a specific one to launch a video? Thanks!

推荐答案

在 Intent 上使用 setDataAndType

Use setDataAndType on the Intent

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newVideoPath));
intent.setDataAndType(Uri.parse(newVideoPath), "video/mp4");
startActivity(intent);

使用视频/mp4";作为 MIME 或使用video/*"如果你不知道类型.

Use "video/mp4" as MIME or use "video/*" if you don't know the type.

这不适用于一般用途.它修复了旧 HTC 设备中的一个错误,该错误需要在意图构造函数中使用 URI 并在之后设置.

This not valid for general use. It fixes a bug in old HTC devices which required the URI in both the intent constructor and be set afterwards.

这篇关于播放视频的Android意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆