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.A开发者_开发问答CTION_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
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!
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.
Try like this:
FileInputStream fis = new FileInputStream(new File(movieurl));
MediaPlayer mp = new MediaPlayer();
mediaPlayer.setDataSource(fis.getFD());
fis.close();
mp.prepare();
mp.start();
精彩评论