Problem using Runnable

1

I am using the video player from link where I have a problem in the next class link

With the following method:

protected Runnable updateTimeRunnable = new Runnable() {
    public void run() {
        updateCounter();

        TIME_THREAD.postDelayed(this, 200);
    }
};

Configure media player with the setLooping method so that the video is restarted upon completion. my problem is that when the video is restarted, only the updateCounter method that is being called from the run method is executed once. As you can see, the updateCounter method is the one that updates the seconds of the video. at the moment of restarting the video, it is left only in the second one, and it does not happen there. Note that when restarting the video I'm restarting the second 2 with seekTo ();.

    
asked by Eduardo Jesus 06.11.2016 в 20:27
source

1 answer

1

The method updateCounter() ; is the one that updates the counter, within this method the variable to update to restart the counter and the Seekbar is:

 int elapsed = getCurrentPosition();

To force the playback position to start from 0, you can do it with seekTo(0) .

I see that your class implements MediaPlayer.OnPreparedListener therefore within the onPrepared() method you could restart the counter:

@Override
synchronized public void onPrepared(MediaPlayer mp) {
    Log.d(TAG, "onPrepared called");
    seekTo(0);
    videoIsReady = true;
    tryToPrepare();
}
    
answered by 07.11.2016 в 03:31