Reputation: 2798
How can i play a mp4 video from my assets or raw folder with the video intent?
whatever i try i always get :
06-25 14:32:14.070: E/AndroidRuntime(3070): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://mypackage/raw/myvideo }
I tryed:
Intent tostart = new Intent(Intent.ACTION_VIEW);
String movieUrl = "file:///android_asset/myvideo.mp4";
// String movieUrl = "android.resource://" + getPackageName() + "/raw/" + "myvideo.mp4";
tostart.setDataAndType(Uri.parse(movieUrl), "video/*");
startActivity(tostart);
I can only find answers where people use video's from SD's card, is there any option so i can use the raw or assets folder?
Upvotes: 0
Views: 11709
Reputation: 13805
AssetFileDescriptor afd;
try {
afd = getAssets().openFd("videofile/video.3gp");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Here video.3gp is file under folder --- videofile -> is one folder under assets folder
Using mediaplayer you can set this way
mediaPlayer = new MediaPlayer();
if(mediaPlayer.isPlaying()){
mediaPlayer.reset();
}
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);
try {
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd
.getStartOffset(), afd.getLength());
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaPlayer.start();
Upvotes: 1
Reputation: 2930
You can parse video Url from raw folder using this:
Uri.parse("android.resource://com.testvideo/" + R.raw.video);
then try:
Upvotes: 0