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());
}
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;
}
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());
}
}
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;
}
}
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);
}
Aggregations