gpt4 book ai didi

android - 完成后自动重新播放视频

转载 作者:行者123 更新时间:2023-11-30 02:29:12 26 4
gpt4 key购买 nike

我正在做与 Android 应用程序相关的视频播放器。我播放了视频,但我想做当视频完成时,它会在应用程序中自动恢复我该怎么办?我在我的应用程序中使用 VideoView。

    // Displays a video file.
VideoView mVideoView = (VideoView) findViewById(R.id.videoview);

String uriPath = "android.resource://com.example.anket4dammy/"
+ R.raw.dunyagoz;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();

mVideoView.start();

}

@Override
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();

switch (eventaction) {
case MotionEvent.ACTION_DOWN:

// timer.cancel();
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
intent.putExtra("EXIT", false);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

break;


}

return true;
}


@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub

}

最佳答案

试试下面的代码

    // video finish listener
mVideoView
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
// not playVideo
// playVideo();

mp.start();
}
});

关于android - 完成后自动重新播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27500115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com