ビデオを再生する VideoView があり、呼び出します
videoPlayer.setMediaController(new MediaController(this));
メディア コントローラ ボタン (再生、一時停止、進む、戻る) を表示します。問題は、の再生または一時停止ボタンをクリックしたときに、どのように追加のメソッドを追加できるMediaController
かです。
これが私のクラスです:
public class VideoPlayer extends Activity implements OnCompletionListener {
private String filename;
private VideoView videoPlayer;
private MediaPlayer mediaplayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.video_player);
System.gc();
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("video_url");
System.out.println(filename);
videoPlayer = (VideoView) findViewById(R.id.videoPlayer);
videoPlayer.setOnCompletionListener(this);
videoPlayer.setKeepScreenOn(true);
videoPlayer.setVideoPath(filename);
videoPlayer.setMediaController(new MediaController(this));
videoPlayer.requestFocus();
videoPlayer.start();
mediaplayer = new MediaPlayer();
mediaplayer = MediaPlayer.create(
this,
Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.alo));
mediaplayer.start();
}
/** This callback will be invoked when the file is finished playing */
@Override
public void onCompletion(MediaPlayer mp) {
// Statements to be executed when the video finishes.
this.finish();
}
/** Use screen touches to toggle the video between playing and paused. */
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
if (videoPlayer.isPlaying()) {
videoPlayer.pause();
mediaplayer.pause();
} else {
videoPlayer.start();
mediaplayer.start();
}
return true;
} else {
return false;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}