如何播放从资源文件夹中的本地视频文件、夹中、资源、视频

2023-09-06 01:18:59 作者:你别皱眉i

我一直在寻找这一个多星期了,我一直没能做到这一点呢。

I've been looking for this for more than a week, and I haven't been able to do it yet.

我只想玩2秒的持续时间视频作为飞溅介绍给我的应用程序,所以SD卡和URL流媒体解决方案是不可能的。我想将MP4的视频文件在/ RES /原始文件夹(例如)和播放,全屏,没有媒体控制器...它不应该是这么难!

I just want to play a 2 second-duration video as a splash intro to my app, so SD card and URL streaming solutions are not possible. I would like to place the mp4 video file in the /res/raw folder (for example) and play it, full-screen, no media controllers... it shouldn't be so hard!!!

我已经下Android的建议(我试过甚至数)的的 http://developer.android.com/guide/appendix/media-formats.html#core

I've already encoded my video following Android's recommendations (I've tried even several) in http://developer.android.com/guide/appendix/media-formats.html#core

我试过很多不同的解决方案,如下列之一,应该工作:

I've tried lots of different solutions, such as the following one, that should work:

    VideoView videoHolder = (VideoView) this.findViewById(R.id.videoView1);
    videoHolder.setMediaController(new MediaController(this));
    Uri uri = Uri.parse("android.resource://mysite/raw/" + R.raw.intro__video);
    videoHolder.setVideoURI(uri);
    videoHolder.start();

我试过几个URI地址,我认为这个问题是不存在的。 我试过仿真器1.6,2.1和2.33。我试着在三个不同的实际设备。

I've tried several URI addresses, I think that the problem is not there. I've tried emulators 1.6, 2.1 and 2.33. I've tried in three different real devices.

我不知道现在什么尝试。有很多的计算器类似的问题,但只有极少数的答案。这些问题的答案用约为放置视频在SD卡(不situable对我来说),但大部分的线程是没有答案的作者,所以我们不知道他终于成功地做到这一点。

I don't know what to try now. There are a lot of similar questions in StackOverflow, but very few answers. The answers use to be about placing the video in the SD card (not situable for me), but most of the threads are unanswered by the author, so we don't know if he finally managed to do it.

非常感谢你提前。也许这个时候我们就可以回答这个问题一劳永逸: - )

Thank you very much in advance. Maybe this time we could answer this question once and for all:-)

编辑 大部分时间的设备只是保持黑色,视频是不是在玩。 对于一些尝试的编码,设备会显示一个错误对话框,说:这个视频无法播放。 如果视频文件本身会有问题(我不这么认为,因为我已经尝试了很多不同的格式,分辨率和编码),请给我一个证明的视频文件,所以我将能够检查问题就是这样......

EDIT Most of the times the device simply keeps black, the video is not playing. For some of the encodings tried, the device shows an error dialog saying "this video can't be played". If the video file itself would be the problem (I don't think so, because I've tried a lot of different formats, resolutions and encodings), please send me a proved video file so I would be able to check if the problem is just that...

推荐答案

我不认为你正在构建的URI正确。试试这个:

I don't think you're constructing the URI properly. Try this:

Uri uri = Uri.parse("android.resource://mysite/" + R.raw.intro__video);

或者这样的:

or this:

Uri uri = Uri.parse("android.resource://mysite/raw/intro__video");
 
精彩推荐
图片推荐