Play a video from SD card and loop the video using videoView

旧巷老猫 提交于 2019-12-11 06:05:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!