简体   繁体   English

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

[英]How to play a local video from resources folder

I've been looking for this for more than a week, and I haven't been able to do it yet. 我一直在寻找这个超过一个星期,但我还没有做到。

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. 我只想播放2秒的视频作为我的应用程序的启动介绍,因此SD卡和URL流解决方案是不可能的。 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!!! 我想将mp4视频文件放置在/ res / raw文件夹中(例如),并以全屏方式播放它,没有媒体控制器...应该不难!

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 我已经按照http://developer.android.com/guide/appendix/media-formats.html#core的 Android建议(甚至尝试了几次)对视频进行编码。

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();

I've tried several URI addresses, I think that the problem is not there. 我尝试了几个URI地址,但我认为问题不存在。 I've tried emulators 1.6, 2.1 and 2.33. 我已经尝试过模拟器1.6、2.1和2.33。 I've tried in three different real devices. 我已经尝试了三种不同的真实设备。

I don't know what to try now. 我不知道该怎么办。 There are a lot of similar questions in StackOverflow, but very few answers. StackOverflow中有很多类似的问题,但是答案却很少。 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. 答案曾经是关于将视频放入SD卡(对我来说不合适),但是大多数线索都没有得到作者的答复,因此我们不知道他是否最终做到了。

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... 如果视频文件本身就是问题所在(我不这么认为,因为我尝试了很多不同的格式,分辨率和编码),请给我发送经过验证的视频文件,以便我能够检查问题所在就是...

I don't think you're constructing the URI properly. 我认为您没有正确构建URI。 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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM