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:com.murati.oszk.audiobook.ui.MediaItemViewHolder.java
public static int getStateFromController(Activity context) { MediaControllerCompat controller = MediaControllerCompat.getMediaController(context); PlaybackStateCompat pbState = controller.getPlaybackState(); if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) { return MediaItemViewHolder.STATE_NONE; } else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) { return MediaItemViewHolder.STATE_PLAYING; } else {/*from w w w.ja v a 2 s .co m*/ return MediaItemViewHolder.STATE_PAUSED; } }
From source file:org.amahi.anywhere.util.MediaNotificationManager.java
private Notification createNotification() { Log.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/* w ww.j av a 2 s.c o m*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); notificationBuilder.addAction(android.R.drawable.ic_media_previous, mService.getString(R.string.label_previous), mPreviousIntent); addPlayPauseAction(notificationBuilder); notificationBuilder.addAction(android.R.drawable.ic_media_next, mService.getString(R.string.label_next), mNextIntent); MediaDescriptionCompat description = mMetadata.getDescription(); Bitmap audioAlbumArt = mMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART); if (audioAlbumArt == null) { // use a placeholder art while the remote art is being downloaded audioAlbumArt = BitmapFactory.decodeResource(mService.getResources(), R.drawable.default_audiotrack); } notificationBuilder.setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(1) // show only play/pause in compact view .setMediaSession(mSessionToken)).setSmallIcon(getAudioPlayerNotificationIcon()) .setLargeIcon(getAudioPlayerNotificationArtwork(audioAlbumArt)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentIntent(mService.createContentIntent()).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); // setNotificationPlaybackState(notificationBuilder); return notificationBuilder.build(); }
From source file:info.tongrenlu.music.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./*ww w . j a v a 2s .c om*/ */ private void configMediaPlayerState() { Log.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()) { Log.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); } }
From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;//w ww .j av a 2s.c om } 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); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine3.setText(R.string.loading); 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.mylovemhz.simplay.MusicService.java
public void play() { Log.d(TAG_MUSIC_SERVICE, "play()"); if (currentState == State.PREPARED || currentState == State.PAUSED) { mediaPlayer.start();//from ww w . j a v a 2 s . com currentState = State.STARTED; updateSessionState(PlaybackStateCompat.STATE_PLAYING); showNotification(); if (callbacks != null) callbacks.onPlaybackStarted(); } if (currentState == State.STOPPED || currentState == State.COMPLETED) { try { cueTrack(); } catch (IOException e) { stop(); } } }
From source file:com.murati.oszk.audiobook.playback.CastPlayback.java
private void updatePlaybackState() { int status = mRemoteMediaClient.getPlayerState(); int idleReason = mRemoteMediaClient.getIdleReason(); LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status); // Convert the remote playback states to media playback states. switch (status) { case MediaStatus.PLAYER_STATE_IDLE: if (idleReason == MediaStatus.IDLE_REASON_FINISHED) { if (mCallback != null) { mCallback.onCompletion(); }/*from w w w . ja va 2s .c o m*/ } break; case MediaStatus.PLAYER_STATE_BUFFERING: mPlaybackState = PlaybackStateCompat.STATE_BUFFERING; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mPlaybackState); } break; case MediaStatus.PLAYER_STATE_PLAYING: mPlaybackState = PlaybackStateCompat.STATE_PLAYING; setMetadataFromRemote(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mPlaybackState); } break; case MediaStatus.PLAYER_STATE_PAUSED: mPlaybackState = PlaybackStateCompat.STATE_PAUSED; setMetadataFromRemote(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mPlaybackState); } break; default: // case unknown LogHelper.d(TAG, "State default : ", status); break; } }
From source file:info.tongrenlu.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*w w w . j av a 2 s. c om*/ } Log.d(TAG, "updatePlaybackState, playback state=" + state.getState()); mLastPlaybackState = state; mLine3.setText(""); switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); // mPlayPause.setImageDrawable(mPauseDrawable); Glide.with(this).load(R.drawable.ic_pause_white_48dp).into(mPlayPause); mControllers.setVisibility(View.VISIBLE); scheduleProgressUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(View.VISIBLE); mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); // mPlayPause.setImageDrawable(mPlayDrawable); Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause); stopProgressUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause); stopProgressUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(View.INVISIBLE); mLoading.setVisibility(View.VISIBLE); mLine3.setText(R.string.loading); stopProgressUpdate(); break; default: Log.d(TAG, "Unhandled state " + state.getState()); } mSkipNext.setVisibility((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? View.INVISIBLE : View.VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? View.INVISIBLE : View.VISIBLE); }
From source file:com.scooter1556.sms.android.fragment.tv.TvVideoPlayerFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { view.setOnKeyListener(new View.OnKeyListener() { @Override/* ww w. j a v a 2s.com*/ public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (playbackState == PlaybackStateCompat.STATE_PLAYING) { pause(); } else { play(currentMedia); } return true; } } return false; } }); }
From source file:com.example.android.uamp.playback.CastPlayback.java
private void updatePlaybackState() { int status = mRemoteMediaClient.getPlayerState(); int idleReason = mRemoteMediaClient.getIdleReason(); LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status); // Convert the remote playback states to media playback states. switch (status) { case MediaStatus.PLAYER_STATE_IDLE: if (idleReason == MediaStatus.IDLE_REASON_FINISHED) { if (mCallback != null) { mCallback.onCompletion(); }/*from www .j a va2 s . c om*/ } break; case MediaStatus.PLAYER_STATE_BUFFERING: mState = PlaybackStateCompat.STATE_BUFFERING; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } break; case MediaStatus.PLAYER_STATE_PLAYING: mState = PlaybackStateCompat.STATE_PLAYING; setMetadataFromRemote(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } break; case MediaStatus.PLAYER_STATE_PAUSED: mState = PlaybackStateCompat.STATE_PAUSED; setMetadataFromRemote(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } break; default: // case unknown LogHelper.d(TAG, "State default : ", status); break; } }
From source file:net.simno.klingar.playback.CastPlayback.java
private void updatePlaybackState() { int newPlayerState = remoteMediaClient.getPlayerState(); int idleReason = remoteMediaClient.getIdleReason(); Timber.d("updatePlaybackState %s %s", getPlayerState(playerState), getIdleReason(idleReason)); if (newPlayerState == playerState) { return;/* w w w . ja v a 2s . c o m*/ } playerState = newPlayerState; switch (playerState) { case MediaStatus.PLAYER_STATE_IDLE: if (idleReason == MediaStatus.IDLE_REASON_FINISHED) { if (callback != null) { currentPosition = 0; callback.onCompletion(); } } break; case MediaStatus.PLAYER_STATE_BUFFERING: state = PlaybackStateCompat.STATE_BUFFERING; if (callback != null) { callback.onPlaybackStatusChanged(); } break; case MediaStatus.PLAYER_STATE_PLAYING: state = PlaybackStateCompat.STATE_PLAYING; setMetadataFromRemote(); if (callback != null) { callback.onPlaybackStatusChanged(); } break; case MediaStatus.PLAYER_STATE_PAUSED: state = PlaybackStateCompat.STATE_PAUSED; setMetadataFromRemote(); if (callback != null) { callback.onPlaybackStatusChanged(); } break; default: } }