简体   繁体   English

在按下手机上的主页/电源按钮后,Videoview重新启动

[英]Videoview Restarts after pressing home/power button on phone

Below are my codes. 以下是我的代码。 My videoview restarts everytime you press on the home/power button. 每当您按下主页/电源按钮时,我的视频视图就会重新启动。 Are there any way i can make it continue where my video has been playing before pressing the home/power button. 有什么方法可以让我继续播放视频,然后再按Home / Power按钮。

Edited : I have put in the codes mentioned by Bharat. 编辑:我已经输入了巴拉特提到的代码。 But it seems that I'me getting error vd not resolved. 但是似乎我得到的错误vd无法解决。

 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();
}
    }

Try this in your class 在课堂上尝试一下

@Override
protected void onPause() {
    vd.pause();
    super.onPause();
}


@Override
protected void onResume() {
    vd.resume();
    super.onResume();
}

when your activity will go on pause it will pause your video view. 当您的活动继续暂停时,它将暂停您的视频观看。 when your activity will resume it will resume it in on resume. 当您的活动恢复时,它将在恢复时恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM