コード例 #1
0
 private void playNext() {
   if (videoIdx + 1 == VideoCached.getVideoCount()) {
     Toast.makeText(mContext, "已经是最后一个视频文件了", Toast.LENGTH_LONG).show();
     mMediaPlayer.stop();
   } else {
     videoIdx = videoIdx + 1;
     preparePlay();
   }
 }
コード例 #2
0
  private void preparePlay() {
    VideoInfo video = VideoCached.getVideo(videoIdx);
    if (video == null) {
      Toast.makeText(this, "没有视频文件", Toast.LENGTH_LONG).show();
      return;
    }

    if (mMediaPlayer.isPlaying() == true) {
      mMediaPlayer.reset();
    }

    try {

      mMediaPlayer.setDataSource(this, Uri.parse(video.path)); // 设置MediaPlayer的数据源
      mMediaPlayer.prepare();
    } catch (Exception e) {
      Log.e("surfaceCreated", "surfaceCreated exception", e);
    }
  }