Created
August 21, 2017 22:09
-
-
Save nazmulidris/aabd75e474cddbdec479fafd5236dc90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void startUpdatingCallbackWithPosition() { | |
| if (mExecutor == null) { | |
| mExecutor = Executors.newSingleThreadScheduledExecutor(); | |
| } | |
| if (mSeekBarPositionUpdateTask == null) { | |
| mSeekBarPositionUpdateTask = new Runnable() { | |
| @Override | |
| public void run() { | |
| updateProgressCallbackTask(); | |
| } | |
| }; | |
| } | |
| mExecutor.scheduleAtFixedRate( | |
| mSeekBarPositionUpdateTask, | |
| 0, | |
| PLAYBACK_POSITION_REFRESH_INTERVAL_MS, | |
| TimeUnit.MILLISECONDS | |
| ); | |
| } | |
| private void stopUpdatingCallbackWithPosition(boolean resetUIPlaybackPosition) { | |
| if (mExecutor != null) { | |
| mExecutor.shutdownNow(); | |
| mExecutor = null; | |
| mSeekBarPositionUpdateTask = null; | |
| if (resetUIPlaybackPosition && mPlaybackInfoListener != null) { | |
| mPlaybackInfoListener.onPositionChanged(0); | |
| } | |
| } | |
| } | |
| private void updateProgressCallbackTask() { | |
| if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { | |
| int currentPosition = mMediaPlayer.getCurrentPosition(); | |
| if (mPlaybackInfoListener != null) { | |
| mPlaybackInfoListener.onPositionChanged(currentPosition); | |
| } | |
| } | |
| } | |
| @Override | |
| public void initializeProgressCallback() { | |
| final int duration = mMediaPlayer.getDuration(); | |
| if (mPlaybackInfoListener != null) { | |
| mPlaybackInfoListener.onDurationChanged(duration); | |
| mPlaybackInfoListener.onPositionChanged(0); | |
| logToUI(String.format("firing setPlaybackDuration(%d sec)", | |
| TimeUnit.MILLISECONDS.toSeconds(duration))); | |
| logToUI("firing setPlaybackPosition(0)"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment