问题
My goal here is to play all the videos from a folder in SDCard for example all the videos in the download folder and play it on loop. But my problem now is when i start the app, the app always shows an error say "Can't play this video".
This is my code and i appreciate the help.
@Override
protected void onResume() {
super.onResume();
VideoView video = (VideoView) findViewById(R.id.videoview1);
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
video.setVideoPath("/storage/extSdCard/Download/great.mp4");
video.start();
}
回答1:
Check code may this will work for you.
@Override
protected void onResume() {
super.onResume();
Uri videoUri =Uri.fromFile(new File("/storage/extSdCard/Download/great.mp4"))
//set the uri of the video to be played
video.setVideoURI(videoUri);
video.start();
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
}
来源:https://stackoverflow.com/questions/50441508/play-a-video-from-sd-card-and-loop-the-video-using-videoview