Search code examples
androidandroid-videoviewseekbar

After pausing the video , Video is not updating in videoView while the seekbar is dragged to new position


This is a sample code of the app i am developing .

This is my class file . . . .

public void onCreate(Bundle icicle) 
   {
     super.onCreate(icicle);
     setContentView(R.layout.main);

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

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

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

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

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



     sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() 
     {  
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) 
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) 
        {
            // TODO Auto-generated method stub

        }

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

        }
    };

And this is my xml file . . . .

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <LinearLayout 
       android:id="@+id/video_ll"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_above="@+id/control_btn_ll"
       android:orientation="horizontal">

        <VideoView
            android:id="@+id/surface_view1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:overScrollMode="always"/>

        <VideoView
            android:id="@+id/surface_view2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:overScrollMode="always"/>

   </LinearLayout>

   <LinearLayout 
       android:id="@+id/control_btn_ll"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_alignParentBottom="true">

       <SeekBar
           android:id="@+id/control_seekbar"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:max="100"
           android:minHeight="1dp"
           android:minWidth="250dp" />

   </LinearLayout>

</RelativeLayout>

I have two videos and have to be updated simultaneously , while dragging the seekbar . The videos should be in pause and i want the vedioView to update to the frame , i drag in the seekbar .

It works fine when the video is playing but not updating when it is in pause .

Thank-you in Advance .


Solution

  • Androids videos dont update the frame after a seek if paused. You have to let the video(s) play for some milliseconds and then pause again. Thats the only way it works afaik.