user1001635
user1001635

Reputation: 3342

video View don't play a local video

hi guys i read many example about play video in video view, but no one work for me, i get this error:

java.io.FileNotFoundException: /android.resource:/frt.com.maint/2130968576 (No such file or directory) 

this is my code-------------------------------------------------------------------------:

FileInputStream fi = new FileInputStream("android.resource://frt.com.maint/" + R.raw.videointro);
        MediaPlayer pl = new MediaPlayer();
        pl.setDataSource(fi.getFD());
        pl.prepare();
        pl.start();

MediaPlayer don't have method setVideoURI, i use the first solution that you give me but i still get same error, after i use this code with videoview:

Uri video = Uri.parse("android.resource://frt.com.maint/videointro");
        vidview_gdf.setVideoURI(video);
        vidview_gdf.start(); 

but i get an error with message "you can not play the video" p.s: additional info: introvideo.mp4 - 7 MB

Upvotes: 1

Views: 1882

Answers (2)

RobGThai
RobGThai

Reputation: 5969

Are you doing this on emulator or actual device?

I had a bit of bad experience with H.264 encoded video before. Basically, I tried to play it on the first GalaxyTab but it didn't work. Turned out that GalaxyTab I had didn't support H.264.

So, I would advise you to make sure that the default video player can play this file before proceed further. If that's not the case for you then I'm not sure what's wrong. Your code looks fine to me.

Upvotes: 0

Simon
Simon

Reputation: 14472

You're trying to use the ID of the resource, which is just an int index.

Use the filename instead:

fi = new FileInputStream("android.resource://frt.com.maint/nitrovideo");

Or better:

StringBuilder videoURIPath = new StringBuilder();
videoURIPath.append("android.resource://");
videoURIPath.append(getPackageName() + "/");
videoURIPath.append("raw/");
videoURIPath.append(videoFileName);
pl.setVideoURI(Uri.parse(videoURIPath.toString());

Where videoFileName is a string of the name of your file.

Upvotes: 2

Related Questions