Example usage for android.media.session PlaybackState STATE_STOPPED

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

Introduction

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

Prototype

int STATE_STOPPED

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

Click Source Link

Document

State indicating this item is currently stopped.

Usage

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

@Override
public void stop(boolean notifyListeners) {
    try {/*  www . jav  a  2  s.c om*/
        upnpPlayer.toStop();
        mCurrentPosition = (int) upnpPlayer.getCurrentMediaPosition();
    } catch (Exception e) {
        e.printStackTrace();
        mCurrentPosition = 0;
    }
    mState = PlaybackState.STATE_STOPPED;
    if (notifyListeners && mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}

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

@Override
public void stop(boolean notifyListeners) {
    castManager.removeVideoCastConsumer(castConsumer);
    state = PlaybackState.STATE_STOPPED;
    if (notifyListeners && callback != null)
        callback.onPlaybackStatusChanged(state);
}

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

@Override
public void stop(boolean notifyListeners) {
    mCastManager.removeVideoCastConsumer(mCastConsumer);
    mState = PlaybackState.STATE_STOPPED;
    if (notifyListeners && mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }/*from w  ww .  ja va  2  s.co  m*/
}

From source file:info.tongrenlu.MediaNotificationManager.java

public void onPlaybackStateChanged(PlaybackStateCompat state) {
    mPlaybackState = state;/*from w  w w.  j av a  2s  .c  om*/
    Log.d(TAG, "Received new playback state" + state);
    if (state != null && (state.getState() == PlaybackState.STATE_STOPPED
            || state.getState() == PlaybackState.STATE_NONE)) {
        stopNotification();
    } else {
        Notification notification = createNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}

From source file:com.example.android.supportv4.media.Playback.java

public void stop(boolean notifyListeners) {
    mState = PlaybackState.STATE_STOPPED;
    if (notifyListeners && mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }//from w w  w .  ja  va  2s  . c  o  m
    mCurrentPosition = getCurrentStreamPosition();
    // Give up Audio focus
    giveUpAudioFocus();
    unregisterAudioNoisyReceiver();
    // Relax all resources
    relaxResources(true);
    if (mWifiLock.isHeld()) {
        mWifiLock.release();
    }
}

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

@Override
public void stop(boolean notifyListeners) {
    mState = PlaybackState.STATE_STOPPED;
    if (notifyListeners && mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }//w  ww  .j a  v  a 2  s .  c  o m
    mCurrentPosition = getCurrentStreamPosition();
    // Give up Audio focus
    giveUpAudioFocus();
    unregisterAudioNoisyReceiver();
    // Relax all resources
    relaxResources(true);
    if (mWifiLock.isHeld()) {
        mWifiLock.release();
    }
}

From source file:com.torrenttunes.android.ui.BaseActivity.java

/**
 * Check if the MediaSession is active and in a "playback-able" state
 * (not NONE and not STOPPED)./*www  . ja v  a2s  . co m*/
 *
 * @return true if the MediaSession's state requires playback controls to be visible.
 */
protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = mMediaController;
    if (mediaController == null || mediaController.getMetadata() == null
            || mediaController.getPlaybackState() == null) {
        return false;
    }
    switch (mediaController.getPlaybackState().getState()) {
    case PlaybackState.STATE_ERROR:
    case PlaybackState.STATE_NONE:
    case PlaybackState.STATE_STOPPED:
        return false;
    default:
        return true;
    }
}

From source file:com.example.android.supportv4.media.Playback.java

public void play(QueueItem item) {
    mPlayOnFocusGain = true;//from  w  w  w .  j a  v  a 2s  .  com
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

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

        } catch (IOException ex) {
            Log.e(TAG, "Exception playing song", ex);
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.torrenttunes.android.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;/* w w w.j av a  2 s.  co  m*/
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

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

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

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

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;//  ww w  . j a v a2 s.c  o m
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider.getMusic(item.getDescription().getMediaId());

        String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);
            mMediaPlayer.prepareAsync();

            mWifiLock.acquire();

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

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}