List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_PLAYING
int STATE_PLAYING
To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_PLAYING.
Click Source Link
From source file:org.runbuddy.tomahawk.ui.fragments.PlaybackFragment.java
/** * Called every time an item inside a ListView or GridView is clicked * @param view the clicked view/*w ww .jav a 2 s . co m*/ * @param item the Object which corresponds to the click * @param segment */ @Override public void onItemClick(View view, Object item, Segment segment) { if (getMediaController() == null) { Log.d(TAG, "onItemClick failed because getMediaController() is null"); return; } if (item instanceof PlaylistEntry) { PlaylistEntry entry = (PlaylistEntry) item; if (entry.getQuery().isPlayable()) { if (getPlaybackManager().getCurrentEntry() == entry) { // if the user clicked on an already playing track int playState = getMediaController().getPlaybackState().getState(); if (playState == PlaybackStateCompat.STATE_PLAYING) { getMediaController().getTransportControls().pause(); } else if (playState == PlaybackStateCompat.STATE_PAUSED) { getMediaController().getTransportControls().play(); } } else { getPlaybackManager().setCurrentEntry(entry); } } } }
From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from w w w . j av a2 s. co m*/ } mLastPlaybackState = state; String castName = mMediaController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); String line3Text = ""; if (castName != null) { line3Text = getResources().getString(R.string.casting_to_device, castName); } mLine3.setText(line3Text); switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPauseDrawable); mControllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine3.setText(R.string.loading); stopSeekbarUpdate(); break; default: LogHelper.d(TAG, "Unhandled state ", state.getState()); } mSkipNext.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); }
From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java
private void addPlayPauseAction(NotificationCompat.Builder builder) { String label;//w w w. j av a 2 s . co m int icon; PendingIntent intent; if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { label = "pause"; icon = R.drawable.ic_pause_white_24dp; intent = mPauseIntent; } else { label = "play"; icon = R.drawable.ic_play_arrow_white_24dp; intent = mPlayIntent; } builder.addAction(new NotificationCompat.Action(icon, label, intent)); }
From source file:info.tongrenlu.music.LocalPlayback.java
/** * Called by AudioManager on audio focus changes. * Implementation of {@link android.media.AudioManager.OnAudioFocusChangeListener} */// w ww .j a v a2 s . c om @Override public void onAudioFocusChange(int focusChange) { Log.d(TAG, "onAudioFocusChange. focusChange=" + focusChange); if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { // We have gained focus: mAudioFocus = AUDIO_FOCUSED; } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { // We have lost focus. If we can duck (low playback volume), we can keep playing. // Otherwise, we need to pause the playback. boolean canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK; mAudioFocus = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK; // If we are playing, we need to reset media player by calling configMediaPlayerState // with mAudioFocus properly set. if (mState == PlaybackStateCompat.STATE_PLAYING && !canDuck) { // If we don't have audio focus and can't duck, we save the information that // we were playing, so that we can resume playback once we get the focus back. mPlayOnFocusGain = true; } } else { Log.e(TAG, "onAudioFocusChange: Ignoring unsupported focusChange: " + focusChange); } configMediaPlayerState(); }
From source file:com.classiqo.nativeandroid_32bitz.MediaNotificationManager.java
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { LogHelper.d(TAG, "updateNotificationPlaybackState. mPlaybackState = " + mPlaybackState); if (mPlaybackState == null || !mStarted) { LogHelper.d(TAG, "updateNotificationPlaybackState. cancelling notification!"); mService.stopForeground(true);//from w ww. j a v a 2s. c o m return; } if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) { LogHelper.d(TAG, "updateNotificationPlaybackState. updating playback position to ", (System.currentTimeMillis() - mPlaybackState.getPosition()) / 1000, "seconds"); builder.setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()).setShowWhen(true) .setUsesChronometer(true); } else { LogHelper.d(TAG, "updateNotificationPlaybackState. hiding playback position"); builder.setWhen(0).setShowWhen(false).setUsesChronometer(false); } builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); }
From source file:com.allthatseries.RNAudioPlayer.Playback.java
/** * Called when MediaPlayer has completed a seek * * @see OnSeekCompleteListener/*from w ww .j a v a 2s . co m*/ */ @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); } }
From source file:androidx.media.MediaUtils2.java
static int createPlaybackStateCompatState(int playerState, int bufferingState) { switch (playerState) { case MediaPlayerBase.PLAYER_STATE_PLAYING: switch (bufferingState) { case MediaPlayerBase.BUFFERING_STATE_BUFFERING_AND_STARVED: return PlaybackStateCompat.STATE_BUFFERING; }/*from w ww . j a v a 2s. c o m*/ return PlaybackStateCompat.STATE_PLAYING; case MediaPlayerBase.PLAYER_STATE_PAUSED: return PlaybackStateCompat.STATE_PAUSED; case MediaPlayerBase.PLAYER_STATE_IDLE: return PlaybackStateCompat.STATE_NONE; case MediaPlayerBase.PLAYER_STATE_ERROR: return PlaybackStateCompat.STATE_ERROR; } // For unknown value return PlaybackStateCompat.STATE_ERROR; }
From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*w w w .ja va2s.c om*/ } mLastPlaybackState = state; if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) { String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); String line3Text = castName == null ? "" : getResources().getString(R.string.casting_to_device, castName); mLine3.setText(line3Text); } switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPauseDrawable); mControllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine3.setText(R.string.loading); stopSeekbarUpdate(); break; default: LogHelper.d(TAG, "Unhandled state ", state.getState()); } mSkipNext.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); }
From source file:com.example.android.leanback.PlaybackTransportControlGlueSample.java
/** * Helper function to create a playback state based on current adapter's state. * * @return playback state compat builder *//* ww w . java 2 s. c om*/ private PlaybackStateCompat createPlaybackStateBasedOnAdapterState() { PlaybackStateCompat.Builder playbackStateCompatBuilder = new PlaybackStateCompat.Builder(); long currentPosition = getCurrentPosition(); long bufferedPosition = getBufferedPosition(); // In this glue we only support normal speed float playbackSpeed = NORMAL_SPEED; // Translate player adapter's state to play back state compat // If player adapter is not prepared // ==> STATE_STOPPED // (Launcher can only visualize the media session under playing state, // it makes more sense to map this state to PlaybackStateCompat.STATE_STOPPED) // If player adapter is prepared // If player is playing // ==> STATE_PLAYING // If player is not playing // ==> STATE_PAUSED if (!getPlayerAdapter().isPrepared()) { playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_STOPPED, currentPosition, playbackSpeed) .setActions(getPlaybackStateActions()); } else if (getPlayerAdapter().isPlaying()) { playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_PLAYING, currentPosition, playbackSpeed) .setActions(getPlaybackStateActions()); } else { playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_PAUSED, currentPosition, playbackSpeed) .setActions(getPlaybackStateActions()); } // always fill buffered position return playbackStateCompatBuilder.setBufferedPosition(bufferedPosition).build(); }
From source file:com.bayapps.android.robophish.playback.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.//from w w w. j a v a2 s . c om */ 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 == PlaybackStateCompat.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 = PlaybackStateCompat.STATE_PLAYING; } else { mMediaPlayer.seekTo(mCurrentPosition); mState = PlaybackStateCompat.STATE_BUFFERING; } } mPlayOnFocusGain = false; } } if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } }