1

After searching for many hours , i am asking this, any related answers are welcomed . .

I'm having a video in my R.raw folder and i am playing it in two videoview of same duration simultaneously , here is my code ,

     sb = (SeekBar)findViewById(R.id.control_seekbar);

     mVideoView1 = (VideoView) findViewById(R.id.surface_view1);
     mVideoView1.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play1);              
     mVideoView1.start();

     mVideoView2 = (VideoView) findViewById(R.id.surface_view2);
     mVideoView2.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play2);              
     mVideoView2.start();

     v1 = mVideoView1.getDuration();
     v2 = mVideoView2.getDuration();

     mVideoView1.setOnPreparedListener(new OnPreparedListener() 
     {
        @Override
        public void onPrepared(MediaPlayer arg0) 
        {
            sb.setMax(mVideoView1.getDuration()+3);
            sb.postDelayed(onEverySecond, 60);
        }
     });

     sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() 
     {  
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) 
        {
            mVideoView1.seekTo(sb.getProgress());
            mVideoView2.seekTo(sb.getProgress());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) 
        {
            mVideoView1.seekTo(sb.getProgress());
            mVideoView2.seekTo(sb.getProgress());
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) 
        {
            mVideoView1.seekTo(progress);
            mVideoView2.seekTo(progress);
        }

    });

   }

   private Runnable onEverySecond=new Runnable() 
   {
        @Override
        public void run() 
        {
            if(sb != null) 
            {
                sb.setProgress(mVideoView1.getCurrentPosition());
            }

            if(mVideoView1.isPlaying()) 
            {
                sb.postDelayed(onEverySecond, 1000);
                if(mVideoView1.getDuration() <= sb.getProgress())
                {
                    mVideoView1.seekTo(0);
                    mVideoView2.seekTo(0);
                }
            }
        }
    };

and i could drag the seekbar to the new position and it is playing from the new position correctly .

But i dont want to play the video initially . It should be in pause() and as i drag the seekbar, the videoview should update to the respective position .

When i change the mVideoView.start() to pause() , i could see only a blank black screen and no update for the seekbar position change in the videoview .

in what way i could achieve it .

VIGNESH
  • 2,023
  • 8
  • 31
  • 46

2 Answers2

3

You have to put a media controller in your videoview.

MediaController mediaController = new MediaController(context);
myVideoView.setMediaController(mediaController).

Now when you click on your video the play, pause buttons will show.

Tooroop
  • 1,824
  • 1
  • 20
  • 31
  • but could i set the same mediacontroller for both the videos ? i tried it but i could not set it for both the videos . – VIGNESH Dec 13 '12 at 07:12
  • hmmm...why not? did you try making two different instances of the MediaController and then adding one MediaController to one VideoView and the other one to the other VideoView? – Tooroop Dec 13 '12 at 08:15
  • oh sorry, now i see I didn't really understand your comment. You could try setting the same controller on both VideoViews. But the you would start and stop the videos at the same time. You won't have controll over every VideoView individually. – Tooroop Dec 13 '12 at 09:46
  • yes , i dont need to control both the videoviews individually . Both videos are of same duration and i want to control both the videos using same mediacontroller but when i set it for two videoviews only the later videoview which is set with the MC works and the former videoview does not respond . – VIGNESH Dec 13 '12 at 11:50
  • Ah OK I see. Hmm maybe that won't be possbile so easy. You will have to write a custom solution to this. Maybe extending the MediaController class and overriding the onPlay, onPause methods where you play/pause both videoViews. – Tooroop Dec 13 '12 at 11:53
0

If you dont want to play the video initially then you need not call start in onCreate() Call it when play button is clicked.

Hope this helps you.

Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22