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.copticchurchlibrary.arabicreader.MediaNotificationManager.java
private void addPlayPauseAction(NotificationCompat.Builder builder) { LogHelper.d(TAG, "updatePlayPauseAction"); String label;/*ww w. ja va2s . co m*/ int icon; PendingIntent intent; if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { label = mService.getString(org.copticchurchlibrary.arabicreader.R.string.label_pause); icon = org.copticchurchlibrary.arabicreader.R.drawable.uamp_ic_pause_white_24dp; intent = mPauseIntent; } else { label = mService.getString(org.copticchurchlibrary.arabicreader.R.string.label_play); icon = org.copticchurchlibrary.arabicreader.R.drawable.uamp_ic_play_arrow_white_24dp; intent = mPlayIntent; } builder.addAction(new NotificationCompat.Action(icon, label, intent)); }
From source file:com.appdevper.mediaplayer.app.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 av a 2s . co 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); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); }
From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;// w w w . j a v a 2s .co m } //TODO: Fix Time for current state mLastPlaybackState = state; MediaControllerCompat controllerCompat = MediaControllerCompat .getMediaController(FullScreenPlayerActivity.this); if (controllerCompat != null && controllerCompat.getExtras() != null) { String castName = controllerCompat.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:net.simno.klingar.playback.LocalPlayback.java
@Override public void onAudioFocusChange(int focusChange) { Timber.d("onAudioFocusChange focusChange %s", focusChange); if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { audioFocus = AUDIO_FOCUSED; // We have gained focus } 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; audioFocus = canDuck ? AUDIO_NO_FOCUS_CAN_DUCK : AUDIO_NO_FOCUS_NO_DUCK; // If we are playing, we need to reset ExoPlayer by calling configExoPlayerState // with audioFocus properly set. if (state == 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. playOnFocusGain = true;//from w w w .j ava 2 s . com } } else { Timber.e("onAudioFocusChange: Ignoring unsupported focusChange: %s", focusChange); } configExoPlayerState(); }
From source file:com.scooter1556.sms.android.activity.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;//from w w w . j a va 2s .c om } lastPlaybackState = state; if (mediaController != null && mediaController.getExtras() != null) { String castName = mediaController.getExtras().getString(MediaService.EXTRA_CONNECTED_CAST); String extraInfo = castName == null ? "" : getResources().getString(R.string.cast_to_device, castName); extra.setText(extraInfo); } switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: loading.setVisibility(INVISIBLE); playPause.setVisibility(VISIBLE); playPause.setImageDrawable(pauseDrawable); controllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: controllers.setVisibility(VISIBLE); loading.setVisibility(INVISIBLE); playPause.setVisibility(VISIBLE); playPause.setImageDrawable(playDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: loading.setVisibility(INVISIBLE); playPause.setVisibility(VISIBLE); playPause.setImageDrawable(playDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: playPause.setVisibility(INVISIBLE); loading.setVisibility(VISIBLE); extra.setText(R.string.state_loading); stopSeekbarUpdate(); break; default: Log.d(TAG, "Unhandled state: " + state.getState()); } skipNext.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); skipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); shuffle.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE) == 0 ? INVISIBLE : VISIBLE); repeat.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SET_REPEAT_MODE) == 0 ? INVISIBLE : VISIBLE); // Custom Actions for (PlaybackStateCompat.CustomAction action : state.getCustomActions()) { switch (action.getAction()) { case MediaService.STATE_SHUFFLE_ON: shuffle.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent)); break; case MediaService.STATE_SHUFFLE_OFF: shuffle.clearColorFilter(); break; case MediaService.STATE_REPEAT_NONE: repeat.setImageResource(R.drawable.ic_repeat_white_24dp); repeat.clearColorFilter(); break; case MediaService.STATE_REPEAT_ALL: repeat.setImageResource(R.drawable.ic_repeat_white_24dp); repeat.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent)); break; case MediaService.STATE_REPEAT_ONE: repeat.setImageResource(R.drawable.ic_repeat_one_white_24dp); repeat.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent)); break; } } }
From source file:org.runbuddy.tomahawk.utils.MediaNotification.java
private void updatePlayPauseAction() { Log.d(TAG, "updatePlayPauseAction"); String playPauseLabel;/* w w w .j av a2s . c o m*/ int playPauseIcon; if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { playPauseLabel = mService.getString(R.string.playback_pause); playPauseIcon = R.drawable.ic_av_pause; } else { playPauseLabel = mService.getString(R.string.playback_play); playPauseIcon = R.drawable.ic_av_play_arrow; } if (mPlayPauseAction == null) { mPlayPauseAction = new NotificationCompat.Action.Builder(playPauseIcon, playPauseLabel, mIntents.get(playPauseIcon)).build(); } else { mPlayPauseAction.icon = playPauseIcon; mPlayPauseAction.title = playPauseLabel; mPlayPauseAction.actionIntent = mIntents.get(playPauseIcon); } }
From source file:com.example.android.uamp.playback.LocalPlayback.java
/** * Called when MediaPlayer has completed a seek * * @see OnSeekCompleteListener//from w ww . j a v a2 s . c om */ @Override public void onSeekComplete(MediaPlayer mp) { LogHelper.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition()); mCurrentPosition = mp.getCurrentPosition(); if (mState == PlaybackStateCompat.STATE_BUFFERING) { registerAudioNoisyReceiver(); mMediaPlayer.start(); mState = PlaybackStateCompat.STATE_PLAYING; } if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } }
From source file:com.scooter1556.sms.android.manager.MediaNotificationManager.java
private int addActions(final NotificationCompat.Builder notificationBuilder) { int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((playbackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mediaService.getString(R.string.label_previous), previousIntent); /*//from ww w .j av a 2 s. c o m * If there is a "skip to previous" button, the play/pause button will * be the second one. We need to keep track of it, because the MediaStyle notification * requires to specify the index of the buttons (actions) that should be visible * when in compact view. */ playPauseButtonPosition = 1; } // Play or pause button, depending on the current state. final String label; final int icon; final PendingIntent intent; if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING) { label = mediaService.getString(R.string.label_pause); icon = R.drawable.ic_pause_white_24dp; intent = pauseIntent; } else { label = mediaService.getString(R.string.label_play); icon = R.drawable.ic_play_arrow_white_24dp; intent = playIntent; } notificationBuilder.addAction(new NotificationCompat.Action(icon, label, intent)); // If skip to next action is enabled if ((playbackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mediaService.getString(R.string.label_next), nextIntent); } return playPauseButtonPosition; }
From source file:nuclei.media.MediaNotificationManager.java
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { LOG.d("updateNotificationPlaybackState. mPlaybackState=", mPlaybackState); if (mPlaybackState == null || !mStarted) { LOG.d("updateNotificationPlaybackState. cancelling notification!"); mService.stopForeground(true);/* w w w .j a v a2 s . com*/ return; } if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) { LOG.d("updateNotificationPlaybackState. updating playback position to ", (System.currentTimeMillis() - mPlaybackState.getPosition()) / MILLI, " seconds"); builder.setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()).setShowWhen(true) .setUsesChronometer(true); } else { LOG.d("updateNotificationPlaybackState. hiding playback position"); builder.setWhen(0).setShowWhen(false).setUsesChronometer(false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); }
From source file:org.runbuddy.tomahawk.views.PlaybackPanel.java
public void updatePlaybackState(PlaybackStateCompat playbackState) { if (mInitialized) { mProgressBarUpdater.setPlaybackState(playbackState); if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING) { if (mPlayPauseButton.isIndeterminate()) { mPlayPauseButton.setIndeterminate(false); mPlayPauseButton.setColor(getResources().getColor(android.R.color.white)); mPlayPauseButton.resetAnimation(); }// w w w .ja v a2 s . com mPauseButton.setVisibility(VISIBLE); mPlayButton.setVisibility(GONE); mProgressBarUpdater.scheduleSeekbarUpdate(); } else if (playbackState.getState() == PlaybackStateCompat.STATE_PAUSED) { if (mPlayPauseButton.isIndeterminate()) { mPlayPauseButton.setIndeterminate(false); mPlayPauseButton.setColor(getResources().getColor(android.R.color.white)); mPlayPauseButton.resetAnimation(); } mPauseButton.setVisibility(GONE); mPlayButton.setVisibility(VISIBLE); mProgressBarUpdater.stopSeekbarUpdate(); } else if (playbackState.getState() == PlaybackStateCompat.STATE_BUFFERING) { if (!mPlayPauseButton.isIndeterminate()) { mPlayPauseButton.setIndeterminate(true); mPlayPauseButton.setColor(getResources().getColor(R.color.tomahawk_red)); mPlayPauseButton.startAnimation(); } mProgressBarUpdater.stopSeekbarUpdate(); } } }