我试图播放我的SD卡中的视频,并且我希望在接听电话之后发生任何动作后恢复视频 那我该怎么办? 我执行此代码但无法保存视频的当前路径
我无法保存路径 package net.ovtraining.firsttask;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;
public class PlayVideo extends Activity {
private VideoView video_view;
private String[] fileName = {
"google1.webm", "google2.webm", "google3.webm",
"google4.webm", "google5.webm", "google6.webm"};
private List<String> paths;
private int mCurrentPosition = -1;
int mCurrentPath;
private int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video_view = (VideoView) findViewById(R.id.videoView1);
String baseDir = Environment.getExternalStoragePublicDirectory("videos").getAbsolutePath()+"/";
paths = new ArrayList<String>();
for (int i = 0; i < fileName.length; i++) {
paths.add(baseDir + fileName[i]);
}
Log.i("path", baseDir);
if(savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(Constants.CURRENT_POSITION);
}
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video_view);
video_view.setMediaController(mediaController);
}
@Override
protected void onStart() {
play();
video_view.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
play();
}
});
super.onStart();
}
public void play() {
if(count < paths.size()) {
video_view.stopPlayback();
video_view.setVideoPath(paths.get(count));
Log.i("TAG", paths.get(count));
video_view.requestFocus();
video_view.start();
if (mCurrentPosition != -1) {
video_view.seekTo(mCurrentPosition);
}
count++;
}
}
@Override
protected void onPause() {
mCurrentPosition = video_view.getCurrentPosition();
super.onPause();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(Constants.CURRENT_PATH, mCurrentPath);
outState.putInt(Constants.CURRENT_POSITION, mCurrentPosition);
super.onSaveInstanceState(outState);
}
}