private void resumeSync() { if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PREPARED) { int focusGained = audioManager.requestAudioFocus( audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { acquireWifiLockIfNecessary(); setSpeed(Float.parseFloat(UserPreferences.getPlaybackSpeed())); mediaPlayer.start(); if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { mediaPlayer.seekTo(media.getPosition()); } setPlayerStatus(PlayerStatus.PLAYING, media); pausedBecauseOfTransientAudiofocusLoss = false; if (android.os.Build.VERSION.SDK_INT >= 14) { RemoteControlClient remoteControlClient = callback.getRemoteControlClient(); if (remoteControlClient != null) { audioManager.registerRemoteControlClient(remoteControlClient); } } audioManager.registerMediaButtonEventReceiver( new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName())); media.onPlaybackStart(); } else { if (BuildConfig.DEBUG) Log.e(TAG, "Failed to request audio focus"); } } else { if (BuildConfig.DEBUG) Log.d( TAG, "Call to resume() was ignored because current state of PSMP object is " + playerStatus); } }
/** Sets the playback speed. This method is executed on the caller's thread. */ private void setSpeedSync(float speed) { playerLock.lock(); if (media != null && media.getMediaType() == MediaType.AUDIO) { if (mediaPlayer.canSetSpeed()) { mediaPlayer.setPlaybackSpeed((float) speed); if (BuildConfig.DEBUG) Log.d(TAG, "Playback speed was set to " + speed); callback.playbackSpeedChanged(speed); } } playerLock.unlock(); }
/** * 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)); }
private void genericOnBufferingUpdate(int percent) { callback.onBufferingUpdate(percent); }
private boolean genericOnError(Object inObj, int what, int extra) { return callback.onMediaPlayerError(inObj, what, extra); }
private boolean genericInfoListener(int what) { return callback.onMediaPlayerInfo(what); }