/** * Sets the player status of the PSMP object. PlayerStatus and media attributes have to be set at * the same time so that getPSMPInfo can't return an invalid state (e.g. status is PLAYING, but * media is null). * * <p>This method will notify the callback about the change of the player status (even if the new * status is the same as the old one). * * @param newStatus The new PlayerStatus. This must not be null. * @param newMedia The new playable object of the PSMP object. This can be null. */ private synchronized void setPlayerStatus(PlayerStatus newStatus, Playable newMedia) { Validate.notNull(newStatus); if (BuildConfig.DEBUG) Log.d(TAG, "Setting player status to " + newStatus); this.playerStatus = newStatus; this.media = newMedia; PlaybackStateCompat.Builder sessionState = new PlaybackStateCompat.Builder(); int state; if (playerStatus != null) { switch (playerStatus) { case PLAYING: state = PlaybackStateCompat.STATE_PLAYING; break; case PREPARED: case PAUSED: state = PlaybackStateCompat.STATE_PAUSED; break; case STOPPED: state = PlaybackStateCompat.STATE_STOPPED; break; case SEEKING: state = PlaybackStateCompat.STATE_FAST_FORWARDING; break; case PREPARING: case INITIALIZING: state = PlaybackStateCompat.STATE_CONNECTING; break; case INITIALIZED: case INDETERMINATE: state = PlaybackStateCompat.STATE_NONE; break; case ERROR: state = PlaybackStateCompat.STATE_ERROR; break; default: state = PlaybackStateCompat.STATE_NONE; break; } } else { state = PlaybackStateCompat.STATE_NONE; } sessionState.setState(state, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, getPlaybackSpeed()); callback.statusChanged(new PSMPInfo(playerStatus, media)); }