android 视频连续播放,VideoView实现视频无缝连续播放
该视频播放器采用了较为简单的videoview,基本思想就是用setOnCompletionListener对视频播进行监听,当视频播放完毕之后,播放下一段视频,视频源放在SD卡内的Download文件夹内,具体代码如下:public class MainActivity extends Activity {VideoView videoView;static int pos=1; //静态整型变
该视频播放器采用了较为简单的videoview,基本思想就是用setOnCompletionListener对视频播进行监听,当视频播放完毕之后,播放下一段视频,视频源放在SD卡内的Download文件夹内,具体代码如下:
public class MainActivity extends Activity {
VideoView videoView;
static int pos=1; //静态整型变量用于标记播放到了第几段视频
MediaController mController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.activity_main);
videoView=(VideoView)findViewById(R.id.video);
mController=new MediaController(this);
File video=new File("/mnt/sdcard/Download/video"+pos+".mp4");
if(video.exists())
{
videoView.setVideoPath(video.getAbsolutePath());
/* videoView.setMediaController(mController);
mController.setMediaPlayer(videoView);*/
videoView.requestFocus();
videoView.start();
}
videoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
pos=pos+1; //在这里将视频地址变为下一个
File video2=new File("/mnt/sdcard/Download/video"+pos+".mp4");
if(video2.exists())
{
try {
videoView.setVideoPath(video2.getAbsolutePath());
/*videoView.setMediaController(mController);
mController.setMediaPlayer(videoView);*/
videoView.requestFocus();
videoView.start();
} catch (Exception e) {
e.printStackTrace();
}
}
else
{Toast.makeText(MainActivity.this,"视频播放完毕",Toast.LENGTH_SHORT).show();}
}
});
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
更多推荐
所有评论(0)