thelawnmowerman
thelawnmowerman

Reputation: 12136

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. 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!!!

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

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.

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...

Upvotes: 1

Views: 4066

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

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

Upvotes: 1

Related Questions