Search in sources :

Example 26 with MediaSessionCompat

use of android.support.v4.media.session.MediaSessionCompat in project vlc-android by GeoffreyMetais.

the class PlaybackService method initMediaSession.

private void initMediaSession() {
    final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
    final PendingIntent mbrIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
    final ComponentName mbrName = new ComponentName(this, MediaButtonReceiver.class);
    mSessionCallback = new MediaSessionCallback();
    mMediaSession = new MediaSessionCompat(this, "VLC", mbrName, mbrIntent);
    mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mMediaSession.setCallback(mSessionCallback);
    try {
        mMediaSession.setActive(true);
    } catch (NullPointerException e) {
        // Some versions of KitKat do not support AudioManager.registerMediaButtonIntent
        // with a PendingIntent. They will throw a NullPointerException, in which case
        // they should be able to activate a MediaSessionCompat with only transport
        // controls.
        mMediaSession.setActive(false);
        mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mMediaSession.setActive(true);
    }
    setSessionToken(mMediaSession.getSessionToken());
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Example 27 with MediaSessionCompat

use of android.support.v4.media.session.MediaSessionCompat in project PainlessMusicPlayer by Doctoror.

the class MediaSessionFactoryImpl method newMediaSession.

@NonNull
@Override
public MediaSessionCompat newMediaSession() {
    final MediaSessionCompat mediaSession = new MediaSessionCompat(context, TAG_MEDIA_SESSION, mediaButtonReceiver, mediaButtonIntent);
    mediaSession.setCallback(mediaSessionCallback);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setSessionActivity(PendingIntent.getActivity(context, 1, new Intent(context, sessionActivityClass), PendingIntent.FLAG_UPDATE_CURRENT));
    mediaSession.setActive(true);
    return mediaSession;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) NonNull(android.support.annotation.NonNull)

Example 28 with MediaSessionCompat

use of android.support.v4.media.session.MediaSessionCompat in project PainlessMusicPlayer by Doctoror.

the class MediaBrowserServiceImpl method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mPackageValidator = new PackageValidator(this);
    mMediaBrowser = new MediaBrowserImpl(this);
    mMediaSessionHolder.openSession();
    final MediaSessionCompat mediaSession = mMediaSessionHolder.getMediaSession();
    if (mediaSession != null) {
        setSessionToken(mediaSession.getSessionToken());
    }
}
Also used : MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Example 29 with MediaSessionCompat

use of android.support.v4.media.session.MediaSessionCompat in project malp by gateship-one.

the class NotificationManager method openMediaSession.

private synchronized void openMediaSession() {
    if (mMediaSession == null) {
        mMediaSession = new MediaSessionCompat(mService, mService.getString(R.string.app_name));
        // Check if stream playback is enabled or not
        if (mDismissible) {
            mMediaSession.setCallback(new MALPMediaSessionCallback());
            mVolumeControlProvider = new MALPVolumeControlProvider();
            mVolumeControlProvider.setCurrentVolume(mLastStatus.getVolume());
            mMediaSession.setPlaybackToRemote(mVolumeControlProvider);
        }
        mMediaSession.setActive(true);
        mSessionActive = true;
    }
}
Also used : MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Example 30 with MediaSessionCompat

use of android.support.v4.media.session.MediaSessionCompat in project Timber by naman14.

the class MusicService method setUpMediaSession.

private void setUpMediaSession() {
    mSession = new MediaSessionCompat(this, "Timber");
    mSession.setCallback(new MediaSessionCompat.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(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
}
Also used : MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Aggregations

MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)31 Intent (android.content.Intent)17 PendingIntent (android.app.PendingIntent)16 ComponentName (android.content.ComponentName)10 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)8 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)5 Bundle (android.os.Bundle)4 Context (android.content.Context)3 NotificationCompat (android.support.v4.app.NotificationCompat)3 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)3 KeyEvent (android.view.KeyEvent)3 SuppressLint (android.annotation.SuppressLint)2 NotificationManager (android.app.NotificationManager)2 IntentFilter (android.content.IntentFilter)2 Bitmap (android.graphics.Bitmap)2 NonNull (android.support.annotation.NonNull)2 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)2 NotificationChannel (android.app.NotificationChannel)1 SharedPreferences (android.content.SharedPreferences)1 Canvas (android.graphics.Canvas)1