0

我有两个包含两个不同内容的选项卡。

  • Tab1->视频流
  • Tab2->列表视图。

单击一个listview项目时,我将转到详细信息页面activity。按下后退时,它将移回listview井中。但在后台,正在播放视频(Tab1 内容)。如何阻止这种情况?

我的代码:

...

public void onCreate(Bundle savedInstanceState) {
        // sets the Bundle
        super.onCreate(savedInstanceState);
        // sets the context
        setContentView(R.layout.videostream);
        myVideoView = (VideoView) findViewById(R.id.vview);
        mProgress = new ProgressDialog(this);


        PlayVideo();

    }

    private void PlayVideo() {
        try {

            mProgress = ProgressDialog.show(VideoActivity.this, "",
                    "Buffering video...", true);
            mProgress.setCancelable(true);


            myVideoView.setVideoURI(Uri.parse(vSource));
            myVideoView.setMediaController(new MediaController(this));
            myVideoView.requestFocus();
            myVideoView.setOnPreparedListener(new OnPreparedListener() {

                public void onPrepared(MediaPlayer mp) {
                    mProgress.dismiss();
                    myVideoView.start();
                }
            });

         } catch (Exception e) {

            mProgress.dismiss();
            System.out.println("Video Play Error :" + e.toString());
            finish();

        }

    }

    public void onSaveInstanceState(Bundle outState) {

        mStartTime = myVideoView.getCurrentPosition();
        outState.putInt("restartTime", mStartTime);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        myInt = savedInstanceState.getInt("restartTime");
        myVideoView.seekTo(myInt);

        myVideoView.start();

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);

       // 2 means landscape and 1 means portait mode
       if (newConfig.orientation == 2) {
           mProgress.dismiss();

       }

    }
    @Override
    public void onPause() {
        super.onPause();

        myVideoView.stopPlayback();

    }
    @Override
      public void onResume() {
            super.onResume();

            PlayVideo();
        }
4

2 回答 2

0

在列表的 onItemClickListener 中暂停视频并在 onResume() 中恢复

于 2012-08-17T10:22:17.953 回答
0

桑杰,你可以做一件事,你有两个选项卡。一个包含视频,另一个包含列表视图,当你从一个选项卡移动到另一个选项卡时,你的第一个活动进入 onPause,当你回来时,第一个活动将是 onresume。所以,我认为你必须在 onResume() 中播放视频并在 onPause() 中停止它。

如果它有效,请告诉我。

于 2012-08-17T12:23:30.087 回答