use of android.media.session.MediaSession in project remusic by aa112901.
the class MediaService method setUpMediaSession.
private void setUpMediaSession() {
mSession = new MediaSession(this, "remusic");
mSession.setCallback(new MediaSession.Callback() {
@Override
public void onPause() {
pause();
mPausedByTransientLossOfFocus = false;
}
@Override
public void onPlay() {
play();
}
@Override
public void onSeekTo(long pos) {
seek(pos);
}
@Override
public void onSkipToNext() {
gotoNext(true);
}
@Override
public void onSkipToPrevious() {
prev(false);
}
@Override
public void onStop() {
pause();
mPausedByTransientLossOfFocus = false;
seek(0);
releaseServiceUiAndStop();
}
});
mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
use of android.media.session.MediaSession in project platform_frameworks_base by android.
the class BrowserService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mSession = new MediaSession(this, "com.example.android.musicservicedemo.BrowserService");
setSessionToken(mSession.getSessionToken());
}
use of android.media.session.MediaSession in project TicktockMusic by Lauzy.
the class MusicService method setUpMedia.
private void setUpMedia() {
mMediaPlayer = new MediaPlayer();
mMediaSession = new MediaSession(this, MusicService.SESSION_TAG);
// 设置播放控制回调
mMediaSession.setCallback(mSessionCallback);
setState(PlaybackState.STATE_NONE);
// 设置可接受媒体控制
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
// 设置音频流类型
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
use of android.media.session.MediaSession in project Timber by naman14.
the class WearBrowserService method onCreate.
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
mContext = this;
mSession = new MediaSession(this, "WearBrowserService");
setSessionToken(mSession.getSessionToken());
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
use of android.media.session.MediaSession in project robolectric by robolectric.
the class ShadowMediaSessionManagerTest method getActiveSessions_callsActiveSessionListeners.
@Test
public void getActiveSessions_callsActiveSessionListeners() {
MediaSession mediaSession = new MediaSession(context, "tag");
MediaController mediaController = new MediaController(context, mediaSession.getSessionToken());
final List<MediaController> changedMediaControllers = new ArrayList<>();
Shadows.shadowOf(mediaSessionManager).addOnActiveSessionsChangedListener(changedMediaControllers::addAll, null);
Shadows.shadowOf(mediaSessionManager).addController(mediaController);
assertThat(changedMediaControllers).containsExactly(mediaController);
}
Aggregations