Java Code Examples for android.media.session.MediaSession#setPlaybackState()
The following examples show how to use
android.media.session.MediaSession#setPlaybackState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicService.java From android-music-player with Apache License 2.0 | 7 votes |
@Override public void onCreate() { super.onCreate(); // Start a new MediaSession mSession = new MediaSession(this, "MusicService"); mSession.setCallback(mCallback); mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); setSessionToken(mSession.getSessionToken()); final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this); mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() { @Override public void onPlaybackStatusChanged(PlaybackState state) { mSession.setPlaybackState(state); mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken()); } }); }
Example 2
Source File: MusicService.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); // Start a new MediaSession mSession = new MediaSession(this, "MusicService"); mSession.setCallback(mCallback); mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); setSessionToken(mSession.getSessionToken()); final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this); mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() { @Override public void onPlaybackStatusChanged(PlaybackState state) { mSession.setPlaybackState(state); mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken()); } }); }
Example 3
Source File: NotificationService.java From RoMote with Apache License 2.0 | 5 votes |
private void setUpMediaSession() { mediaSession = new MediaSession(this, TAG); mediaSession.setActive(true); mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setPlaybackState( new PlaybackState.Builder() .setState(PlaybackState.STATE_PLAYING, 0L, 0F) .setActions(PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY | PlaybackState.ACTION_REWIND | PlaybackState.ACTION_FAST_FORWARD) .build()); mediaSession.setMetadata(new MediaMetadata.Builder().build()); }