以下是我的代码。每次按下主页/电源按钮时,我的视频视图都会重新启动。在按下主页/电源按钮之前,有什么方法可以让它继续播放我的视频。
编辑:我已经输入了 Bharat 提到的代码。但似乎我收到错误 vd notsolved。
public class Video1 extends Activity {
private MediaController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videomain);
//AdView adView = (AdView)this.findViewById(R.id.adView);
//adView.loadAd(new AdRequest());
VideoView vd = (VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.opening);
mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
vd.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer mp)
{
Intent intent=new Intent(Video1.this,GalleryVideo.class);
startActivity(intent);
}
});
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
protected void onPause() {
vd.pause(); /**ERROR - vd cannot be resolved**/
super.onPause();
}
@Override
protected void onResume() {
vd.resume(); /**ERROR - vd cannot be resolved**/
super.onResume();
}
}