J J
J J

Reputation: 1600

Intent to play video on Android from file on SD Card

I'm trying to load an intent to play a video file on my phone's SD drive. I'm not sure what I'm doing wrong...

String movieurl = Environment.getExternalStorageDirectory() + "/Videos/Wildlife.wmv";

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

I get an error "File cannot be displayed of played".

Any thoughts?

Note: I've also tried:

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(movieurl);
mp.prepare();
mp.start();

Which fails with exception: java.io.IOException: Prepare failed.: status=0x1

Upvotes: 2

Views: 9102

Answers (3)

J J
J J

Reputation: 1600

Figured it out...

Turns out that on the Droid X2, Environment.getExternalStorageDirectory() returns "/mnt/sdcard", which isn't actually the SD Card.

(Found this out by doing a File.listFiles())

The actual SD Card directory on the Droid X2 is "/mnt/sdcard-ext".

Thanks for the help!

Upvotes: 3

Gabriel Negut
Gabriel Negut

Reputation: 13960

Try like this:

FileInputStream fis = new FileInputStream(new File(movieurl));
MediaPlayer mp = new MediaPlayer();
mediaPlayer.setDataSource(fis.getFD());
fis.close();
mp.prepare();
mp.start();

Upvotes: 1

Femi
Femi

Reputation: 64710

Does the WMV file play by itself in the standard media player? I'd suspect if you continue to get errors that perhaps the file is just not playable.

Upvotes: 1

Related Questions