List of usage examples for android.support.v4.media.session MediaSessionCompat setPlaybackState
public void setPlaybackState(PlaybackStateCompat state)
From source file:com.wojtechnology.sunami.MediaSessionCompatHelper.java
public static void applyState(MediaSessionCompat session, PlaybackStateCompat playbackState) { session.setPlaybackState(playbackState); ensureTransportControls(session, playbackState); }
From source file:com.rks.musicx.services.MediaSession.java
public static void lockscreenMedia(MediaSessionCompat mediaSessionCompat, MusicXService musicXService, String what) {//from w w w.j a v a 2s .com if (musicXService == null) { return; } MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); if (what.equals(PLAYSTATE_CHANGED) || what.equals(META_CHANGED)) { int state = MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying() ? PlaybackStateCompat.STATE_PAUSED : PlaybackStateCompat.STATE_PLAYING; mediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder() .setState(state, musicXService.getPlayerPos(), 1.0f) .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .build()); builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, musicXService.getsongTitle()); builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, musicXService.getDuration()); builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, musicXService.getsongArtistName()); builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, musicXService.getsongAlbumName()); handler.post(new Runnable() { @Override public void run() { ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(), musicXService.getsongAlbumID(), new palette() { @Override public void palettework(Palette palette) { } }, new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); mediaSessionCompat.setMetadata(builder.build()); } @Override public void bitmapfailed(Bitmap bitmap) { builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); mediaSessionCompat.setMetadata(builder.build()); } }); } }); } }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MediaSessionCompat mediaSession = new MediaSessionCompat(this, getApplication().getPackageName()); mediaSession.setCallback(mMediaSessionCallback); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mediaSession.setActive(true);/* www . j av a 2 s . c om*/ PlaybackStateCompat state = new PlaybackStateCompat.Builder().setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS).build(); mediaSession.setPlaybackState(state); }
From source file:android.support.mediacompat.service.ServiceBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras();/*from w w w . j a v a2 s .co m*/ if (ACTION_CALL_MEDIA_BROWSER_SERVICE_METHOD.equals(intent.getAction()) && extras != null) { StubMediaBrowserServiceCompat service = StubMediaBrowserServiceCompat.sInstance; int method = extras.getInt(KEY_METHOD_ID, 0); switch (method) { case NOTIFY_CHILDREN_CHANGED: service.notifyChildrenChanged(extras.getString(KEY_ARGUMENT)); break; case SEND_DELAYED_NOTIFY_CHILDREN_CHANGED: service.sendDelayedNotifyChildrenChanged(); break; case SEND_DELAYED_ITEM_LOADED: service.sendDelayedItemLoaded(); break; case CUSTOM_ACTION_SEND_PROGRESS_UPDATE: service.mCustomActionResult.sendProgressUpdate(extras.getBundle(KEY_ARGUMENT)); break; case CUSTOM_ACTION_SEND_ERROR: service.mCustomActionResult.sendError(extras.getBundle(KEY_ARGUMENT)); break; case CUSTOM_ACTION_SEND_RESULT: service.mCustomActionResult.sendResult(extras.getBundle(KEY_ARGUMENT)); break; case SET_SESSION_TOKEN: StubMediaBrowserServiceCompatWithDelayedMediaSession.sInstance.callSetSessionToken(); break; } } else if (ACTION_CALL_MEDIA_SESSION_METHOD.equals(intent.getAction()) && extras != null) { MediaSessionCompat session = StubMediaBrowserServiceCompat.sSession; int method = extras.getInt(KEY_METHOD_ID, 0); switch (method) { case SET_EXTRAS: session.setExtras(extras.getBundle(KEY_ARGUMENT)); break; case SET_FLAGS: session.setFlags(extras.getInt(KEY_ARGUMENT)); break; case SET_METADATA: session.setMetadata((MediaMetadataCompat) extras.getParcelable(KEY_ARGUMENT)); break; case SET_PLAYBACK_STATE: session.setPlaybackState((PlaybackStateCompat) extras.getParcelable(KEY_ARGUMENT)); break; case SET_QUEUE: List<QueueItem> items = extras.getParcelableArrayList(KEY_ARGUMENT); session.setQueue(items); break; case SET_QUEUE_TITLE: session.setQueueTitle(extras.getCharSequence(KEY_ARGUMENT)); break; case SET_SESSION_ACTIVITY: session.setSessionActivity((PendingIntent) extras.getParcelable(KEY_ARGUMENT)); break; case SET_CAPTIONING_ENABLED: session.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT)); break; case SET_REPEAT_MODE: session.setRepeatMode(extras.getInt(KEY_ARGUMENT)); break; case SET_SHUFFLE_MODE: session.setShuffleMode(extras.getInt(KEY_ARGUMENT)); break; case SEND_SESSION_EVENT: Bundle arguments = extras.getBundle(KEY_ARGUMENT); session.sendSessionEvent(arguments.getString("event"), arguments.getBundle("extras")); break; case SET_ACTIVE: session.setActive(extras.getBoolean(KEY_ARGUMENT)); break; case RELEASE: session.release(); break; case SET_PLAYBACK_TO_LOCAL: session.setPlaybackToLocal(extras.getInt(KEY_ARGUMENT)); break; case SET_PLAYBACK_TO_REMOTE: ParcelableVolumeInfo volumeInfo = extras.getParcelable(KEY_ARGUMENT); session.setPlaybackToRemote(new VolumeProviderCompat(volumeInfo.controlType, volumeInfo.maxVolume, volumeInfo.currentVolume) { }); break; case SET_RATING_TYPE: session.setRatingType(RatingCompat.RATING_5_STARS); break; } } }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.ui.notifications.MediaNotification.java
private static void updateMediaSession(MediaSessionCompat mediaSession) { ExtendedFile currentFile = MediaManager.getInstance().getCurrentFile(); if (currentFile != null) { long validActions = PlaybackStateCompat.ACTION_STOP; if (MediaManager.getInstance().canPlay()) { validActions |= PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE; }// ww w .j a v a 2 s . co m if (MediaManager.getInstance().hasNext()) { validActions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } if (MediaManager.getInstance().hasPrevious()) { validActions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } int playState = MediaManager.getInstance().isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; mediaSession.setMetadata(new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentFile.getParentFile().getName()) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentFile.getNameWithoutExtension()) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, MediaManager.getInstance().getDuration()) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, MediaManager.getInstance().getPlaylist().getCurrentIndex() + 1) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, MediaManager.getInstance().getPlaylist().size()) //.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap) .build()); mediaSession.setPlaybackState(new PlaybackStateCompat.Builder() .setState(playState, MediaManager.getInstance().getPosition(), 1.0f).setActions(validActions) .build()); } else { mediaSession.setActive(false); } }