Example usage for android.media.session PlaybackState STATE_PLAYING

List of usage examples for android.media.session PlaybackState STATE_PLAYING

Introduction

In this page you can find the example usage for android.media.session PlaybackState STATE_PLAYING.

Prototype

int STATE_PLAYING

To view the source code for android.media.session PlaybackState STATE_PLAYING.

Click Source Link

Document

State indicating this item is currently playing.

Usage

From source file:com.appdevper.mediaplayer.app.LocalPlayback.java

/**
 * Reconfigures MediaPlayer according to audio focus settings and
 * starts/restarts it. This method starts/restarts the MediaPlayer
 * respecting the current audio focus state. So if we have focus, it will
 * play normally; if we don't have focus, it will either leave the
 * MediaPlayer paused or set it to a low volume, depending on what is
 * allowed by the current focus settings. This method assumes mPlayer !=
 * null, so if you are calling it, you have to do so from a context where
 * you are sure this is the case.//  w  w  w.j ava2  s . com
 */
private void configMediaPlayerState() {
    LogHelper.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
    if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
        // If we don't have audio focus and can't duck, we have to pause,
        if (mState == PlaybackState.STATE_PLAYING) {
            pause();
        }
    } else { // we have audio focus:
        if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
            mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
        } else {
            if (mMediaPlayer != null) {
                mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
            } // else do something for remote client.
        }
        // If we were playing when we lost focus, we need to resume playing.
        if (mPlayOnFocusGain) {
            if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                LogHelper.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to ", mCurrentPosition);
                if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
                    mMediaPlayer.start();
                    mState = PlaybackState.STATE_PLAYING;
                } else {
                    mMediaPlayer.seekTo(mCurrentPosition);
                    mState = PlaybackState.STATE_BUFFERING;
                }
            }
            mPlayOnFocusGain = false;
        }
    }
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}

From source file:com.classiqo.nativeandroid_32bitz.playback.LocalPlayback.java

@Override
public void onAudioFocusChange(int focusChange) {
    LogHelper.d(TAG, "onAudioFocusChange. focusChange = ", focusChange);

    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        mAudioFocus = AUDIO_FOCUSED;/*from   w w  w . j  a  v a  2s  . c  o  m*/
    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
        mAudioFocus = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK;

        if (mState == PlaybackState.STATE_PLAYING && !canDuck) {
            mPlayOnFocusGain = true;
        }
    } else {
        LogHelper.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: ", focusChange);
    }
    configMediaPlayerState();
}

From source file:com.orangesoft.jook.CastPlayback.java

private void updatePlaybackState() {
    int status = castManager.getPlaybackStatus();
    int idleReason = castManager.getIdleReason();

    Log.d(TAG, "onRemoteMediaPlayerStatusUpdated " + status);

    // Convert the remote playback states to media playback states.
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        if (idleReason == MediaStatus.IDLE_REASON_FINISHED) {
            if (callback != null)
                callback.onCompletion();
        }/*from  w w w .j  av a 2s.c  om*/
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        safeStatusChangeNotification(PlaybackState.STATE_BUFFERING);
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        safeStatusChangeNotification(PlaybackState.STATE_PLAYING);
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        safeStatusChangeNotification(PlaybackState.STATE_PAUSED);
        break;
    }
}

From source file:com.appdevper.mediaplayer.app.CastPlayback.java

private void updatePlaybackState() {
    int status = mCastManager.getPlaybackStatus();
    int idleReason = mCastManager.getIdleReason();

    LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status);

    // Convert the remote playback states to media playback states.
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        if (idleReason == MediaStatus.IDLE_REASON_FINISHED) {
            if (mCallback != null) {
                mCallback.onCompletion();
            }/* w  ww. j  av a  2s  . c  o m*/
        }
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        mState = PlaybackState.STATE_PLAYING;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        mState = PlaybackState.STATE_PAUSED;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    default: // case unknown
        LogHelper.d(TAG, "State default : ", status);
        break;
    }
}

From source file:com.classiqo.nativeandroid_32bitz.playback.LocalPlayback.java

@Override
public void onSeekComplete(MediaPlayer mp) {
    LogHelper.d(TAG, "onSeekComplete from MediaPlayer: ", mp.getCurrentPosition());

    mCurrentPosition = mp.getCurrentPosition();

    if (mState == PlaybackState.STATE_BUFFERING) {
        registerAudioNoisyReceiver();/*from ww w . j  ava 2 s  .  com*/
        mMediaPlayer.start();
        mState = PlaybackState.STATE_PLAYING;
    }

    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}

From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private long getAvailableActions(int nextState) {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID
            | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT
            | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_PAUSE;

    if (nextState == PlaybackState.STATE_PLAYING) {
        actions |= PlaybackState.ACTION_PAUSE;
    }/*from   www .  ja va 2 s  .c o  m*/

    return actions;
}

From source file:org.amahi.anywhere.tv.fragment.TvPlaybackVideoFragment.java

public void playbackStateChanged() {
    if (mCurrentPlaybackState != PlaybackState.STATE_PLAYING) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
        }/*from ww w  .j a va 2 s  .co m*/
        startProgressAutomation();
        setFadingEnabled(true);
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PAUSE);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PAUSE));
        notifyChanged(mPlayPauseAction);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
        }
        stopProgressAutomation();
        setFadingEnabled(false);
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PLAY);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PLAY));
        notifyChanged(mPlayPauseAction);
    }
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private long getAvailableActions(int nextState) {

    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID
            | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT
            | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_PAUSE;

    if (nextState == PlaybackState.STATE_PLAYING) {

        actions |= PlaybackState.ACTION_PAUSE;

    }/*from  w ww  .  j av a2s  .c  o  m*/

    return actions;
}

From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private void playPause(boolean doPlay) {
    if (getPlaybackState() == PlaybackState.STATE_NONE) {
        setupCallbacks();// w ww .  j  a  va2  s. c o m
    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {
        if (mPosition > 0) {
            mVideoView.seekTo(mPosition);
        }
        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);
    } else {
        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);
    }
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private void playPause(boolean doPlay) {

    if (getPlaybackState() == PlaybackState.STATE_NONE) {

        setupCallbacks();//from ww  w.  j  a v a 2  s.c om

    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {

        if (mPosition > 0) {

            mVideoView.seekTo(mPosition);

        }

        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);

    } else {

        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);

    }

}