private void setUpMediaSession() { mSession = new MediaSessionCompat(this, "Timber"); mSession.setCallback(new MediaSessionCompat.Callback() { @Override public void onPause() { mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
/** * Updates the metadata of the media session. * * <p>Apps normally only need to call this method when the backing data for a given media item has * changed and the metadata should be updated immediately. */ public final void invalidateMediaSessionMetadata() { if (mediaMetadataProvider != null && player != null) { mediaSession.setMetadata(mediaMetadataProvider.getMetadata(player)); } }
public MediaSessionManager(@NonNull final Context context, @NonNull final Player player, @NonNull final MediaSessionCallback callback) { this.mediaSession = new MediaSessionCompat(context, TAG); this.mediaSession.setActive(true); this.sessionConnector = new MediaSessionConnector(mediaSession, new PlayQueuePlaybackController(callback)); this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback)); this.sessionConnector.setPlayer(player, null); }
private void initializeMediaSession() { mSession = new MediaSessionCompat(this, TAG); mSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mSession.setActive(true); MediaControllerCompat.setMediaController(this, mSession.getController()); MediaMetadataCompat metadata = new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle()) .build(); mSession.setMetadata(metadata); MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView); mSession.setCallback(mMediaSessionCallback); int state = mMovieView.isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; updatePlaybackState( state, MEDIA_ACTIONS_ALL, mMovieView.getCurrentPosition(), mMovieView.getVideoResourceId()); }
private MediaSessionCompat createMediaSession(Context context) { // create a media session MediaSessionCompat session = new MediaSessionCompat(context, LOG_TAG); session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); session.setPlaybackState(createSessionPlaybackState()); session.setCallback(new MediaSessionCallback()); setSessionToken(session.getSessionToken()); return session; }
private void initMediaSession() { ComponentName componentName = new ComponentName(this, MediaButtonReceiver.class); mMediaSession = new MediaSessionCompat( getApplicationContext(), "Tomahawk", componentName, null); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); Intent intent = new Intent(PlaybackService.this, TomahawkMainActivity.class); intent.setAction(TomahawkMainActivity.SHOW_PLAYBACKFRAGMENT_ON_STARTUP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mMediaSession.setSessionActivity(pendingIntent); HandlerThread thread = new HandlerThread("playbackservice_callback"); thread.start(); mCallbackHandler = new Handler(thread.getLooper()); mMediaSession.setCallback(mMediaSessionCallback, mCallbackHandler); mMediaSession.setRatingType(RatingCompat.RATING_HEART); Bundle extras = new Bundle(); extras.putString(EXTRAS_KEY_PLAYBACKMANAGER, mPlaybackManager.getId()); mMediaSession.setExtras(extras); updateMediaPlayState(); setSessionToken(mMediaSession.getSessionToken()); MediaImageHelper.get().addListener(mMediaImageLoadedListener); }
private void createMediaSession() { mMediaSession = new MediaSessionCompat(this, "kdeconnect"); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mMediaSession.setPlaybackState(new PlaybackStateCompat.Builder() .setState(PlaybackStateCompat.STATE_PLAYING, 0, 0) .build()); mMediaSession.setPlaybackToRemote(getVolumeProvider()); mMediaSession.setActive(true); }
public void release() { mMediaSession.setCallback(null); mMediaSession.setActive(false); mMediaSession.release(); }
public PlaybackServiceStatusHelper(PlaybackService playbackService) { mPlaybackService = playbackService; // Get MediaSession objects mMediaSession = new MediaSessionCompat(mPlaybackService, "OdysseyPBS"); // Register the callback for the MediaSession mMediaSession.setCallback(new OdysseyMediaSessionCallback()); mCoverLoader = new CoverBitmapLoader(mPlaybackService, new BitmapCoverReceiver()); // Register the button receiver PendingIntent mediaButtonPendingIntent = PendingIntent.getBroadcast(mPlaybackService, 0, new Intent(mPlaybackService, RemoteControlReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); mMediaSession.setMediaButtonReceiver(mediaButtonPendingIntent); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS + MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); // Initialize the notification manager mNotificationManager = new OdysseyNotificationManager(mPlaybackService); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(playbackService); mHideArtwork = sharedPref.getBoolean(playbackService.getString(R.string.pref_hide_artwork_key), playbackService.getResources().getBoolean(R.bool.pref_hide_artwork_default)); hideMediaOnLockscreen(sharedPref.getBoolean(playbackService.getString(R.string.pref_hide_media_on_lockscreen_key), playbackService.getResources().getBoolean(R.bool.pref_hide_media_on_lockscreen_default))); Intent settingChangedIntent = new Intent(MESSAGE_HIDE_ARTWORK_CHANGED); settingChangedIntent.putExtra(MESSAGE_EXTRA_HIDE_ARTWORK_CHANGED_VALUE, mHideArtwork); mPlaybackService.sendBroadcast(settingChangedIntent); }
private void updateMediaSession(Station station, boolean activeState) { mSession.setPlaybackState(createSessionPlaybackState()); mSession.setMetadata(getSessionMetadata(getApplicationContext(), station)); mSession.setActive(activeState); }
mSession.release();
initMediaPlayer(); mMediaSession = new MediaSessionCompat(this, LOG_TAG); setSessionToken(mMediaSession.getSessionToken()); mMediaSession.setCallback(new MediaSessionCompat.Callback() { @Override public void onPlay() {
private void releaseServiceUiAndStop() { if (isPlaying() || mPausedByTransientLossOfFocus || mPlayerHandler.hasMessages(TRACK_ENDED)) { return; } if (D) Log.d(TAG, "Nothing is playing anymore, releasing notification"); cancelNotification(); mAudioManager.abandonAudioFocus(mAudioFocusListener); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mSession.setActive(false); if (!mServiceInUse) { saveQueue(true); stopSelf(mServiceStartId); } }
if (player == null) { builder.setActions(buildPlaybackActions()).setState(PlaybackStateCompat.STATE_NONE, 0, 0, 0); mediaSession.setPlaybackState(builder.build()); return; SystemClock.elapsedRealtime()) .setExtras(extras); mediaSession.setPlaybackState(builder.build());
builder.setVisibility(Notification.VISIBILITY_PUBLIC); android.support.v4.media.app.NotificationCompat.MediaStyle style = new android.support.v4.media.app.NotificationCompat.MediaStyle() .setMediaSession(mSession.getSessionToken()) .setShowActionsInCompactView(0, 1, 2, 3); builder.setStyle(style);
public MediaPlayerSessionController(@NonNull Context context, @NonNull SpotifyPlayerController player) { this.player = player; mNowPlayingSession = new MediaSessionCompat(context, "spotifytv"); mNowPlayingSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); Intent intent = new Intent(context, NowPlayingActivity.class); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mNowPlayingSession.setSessionActivity(pi); // for the MediaBrowserService //setSessionToken(mNowPlayingSession.getSessionToken()); }
public void stopNowPlayingSession() { Timber.d("Stopping now playing session"); if (mNowPlayingSession.isActive()) { mNowPlayingSession.setActive(false); mNowPlayingSession.setCallback(null); } }
@Override public void onPrepare() { if (mQueueIndex < 0 && mPlaylist.isEmpty()) { // Nothing to play. return; } final String mediaId = mPlaylist.get(mQueueIndex).getDescription().getMediaId(); mPreparedMedia = MusicLibrary.getMetadata(MusicService.this, mediaId); mSession.setMetadata(mPreparedMedia); if (!mSession.isActive()) { mSession.setActive(true); } }
private void startNowPlayingSession() { Timber.d("Starting now playing session"); mNowPlayingSession.setActive(true); mNowPlayingSession.setCallback(new MediaButtonReceiver(player)); }