Java Code Examples for android.media.MediaPlayer#getCurrentPosition()

The following examples show how to use android.media.MediaPlayer#getCurrentPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundAudioService.java    From YouTube-In-Background with MIT License 6 votes vote down vote up
@Override
    public void onSeekComplete(MediaPlayer mp)
    {
//        LogHelper.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
        currentPosition = mp.getCurrentPosition();
        if (playState == PlaybackStateCompat.STATE_BUFFERING) {
            registerAudioNoisyReceiver();
            registerMediaButtonReceiver();
            mediaPlayer.start();
            playState = PlaybackStateCompat.STATE_PLAYING;
            updateAction(ACTION_PAUSE);
        }
//        if (callback != null) {
//            callback.onPlaybackStatusChanged(playState);
//        }
    }
 
Example 2
Source File: Playback.java    From react-native-audio-streaming-player with MIT License 5 votes vote down vote up
/**
 * Called when MediaPlayer has completed a seek
 *
 * @see OnSeekCompleteListener
 */
@Override
public void onSeekComplete(MediaPlayer mp) {
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        registerAudioNoisyReceiver();
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStateChanged(mState);
    }
}
 
Example 3
Source File: AudioPlaybackListener.java    From DMAudioStreamer with Apache License 2.0 5 votes vote down vote up
@Override
public void onSeekComplete(MediaPlayer mp) {
    Logger.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        registerAudioNoisyReceiver();
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}
 
Example 4
Source File: Playback.java    From react-native-streaming-audio-player with MIT License 5 votes vote down vote up
/**
 * Called when MediaPlayer has completed a seek
 *
 * @see OnSeekCompleteListener
 */
@Override
public void onSeekComplete(MediaPlayer mp) {
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        registerAudioNoisyReceiver();
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStateChanged(mState);
    }
}
 
Example 5
Source File: MediaServiceBinder.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getCurrentPosition() {
    MediaPlayer currentPlayer = mService.getPlayer();
    if (currentPlayer != null) {
        return currentPlayer.getCurrentPosition();
    } else {
        return 0;
    }
}
 
Example 6
Source File: InlineCarouselCardMediaView.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
private int calculatePercentViewed(final MediaPlayer mp)
{
    final float videoDuration = mp.getDuration();
    final float currentPosition = mp.getCurrentPosition();
    // NOTE: Media player bug: calling getCurrentPosition after the video finished playing gives slightly larger value than the total duration of the video.
    if ( currentPosition >= videoDuration )
    {
        // Video fully watched, return 100%.
        return 100;
    }

    final double percentViewed = ( currentPosition / videoDuration ) * 100f;
    return (int) Math.ceil( percentViewed );
}
 
Example 7
Source File: LocalPlayback.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
/**
 * Called when MediaPlayer has completed a seek
 *
 * @see OnSeekCompleteListener
 */
@Override
public void onSeekComplete(MediaPlayer mp) {
    LogUtils.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}