Search in sources :

Example 1 with MediaSession

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);
}
Also used : MediaSession(android.media.session.MediaSession)

Example 2 with MediaSession

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());
}
Also used : MediaSession(android.media.session.MediaSession)

Example 3 with MediaSession

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);
}
Also used : MediaSession(android.media.session.MediaSession) MediaPlayer(android.media.MediaPlayer)

Example 4 with MediaSession

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);
}
Also used : MediaSession(android.media.session.MediaSession)

Example 5 with MediaSession

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);
}
Also used : MediaController(android.media.session.MediaController) MediaSession(android.media.session.MediaSession) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

MediaSession (android.media.session.MediaSession)16 MediaController (android.media.session.MediaController)4 MediaSessionManager (android.media.session.MediaSessionManager)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 MediaDescription (android.media.MediaDescription)1 MediaMetadata (android.media.MediaMetadata)1 MediaPlayer (android.media.MediaPlayer)1 Rating (android.media.Rating)1 PlaybackState (android.media.session.PlaybackState)1 Handler (android.os.Handler)1 NotificationCompat (android.support.v7.app.NotificationCompat)1 Palette (android.support.v7.graphics.Palette)1 MainActivity (com.freedom.lauzy.ticktockmusic.ui.activity.MainActivity)1 PlayerFragment (com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)1