use of android.support.v4.media.session.MediaSessionCompat in project Shuttle by timusus.
the class MusicService method setupMediaSession.
private void setupMediaSession() {
mediaSession = new MediaSessionCompat(this, "Shuttle", mediaButtonReceiverComponent, null);
mediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPause() {
pause();
pausedByTransientLossOfFocus = false;
}
@Override
public void onPlay() {
play();
}
@Override
public void onSeekTo(long pos) {
seekTo(pos);
}
@Override
public void onSkipToNext() {
gotoNext(true);
}
@Override
public void onSkipToPrevious() {
prev();
}
@Override
public void onStop() {
pause();
pausedByTransientLossOfFocus = false;
releaseServiceUiAndStop();
}
@Override
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
Log.e("MediaButtonReceiver", "OnMediaButtonEvent called");
MediaButtonIntentReceiver.MediaButtonReceiverHelper.onReceive(MusicService.this, mediaButtonEvent);
return true;
}
});
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
// For some reason, MediaSessionCompat doesn't seem to pass all of the available 'actions' on as
// transport control flags for the RCC, so we do that manually
RemoteControlClient remoteControlClient = (RemoteControlClient) mediaSession.getRemoteControlClient();
if (remoteControlClient != null) {
remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
}
}
use of android.support.v4.media.session.MediaSessionCompat in project quran_android by quran.
the class AudioService method onCreate.
@Override
public void onCreate() {
Timber.i("debug: Creating service");
handler = new ServiceHandler(this);
final Context appContext = getApplicationContext();
((QuranApplication) appContext).getApplicationComponent().inject(this);
wifiLock = ((WifiManager) appContext.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "QuranAudioLock");
notificationManager = (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
// create the Audio Focus Helper, if the Audio Focus feature is available
audioFocusHelper = new AudioFocusHelper(appContext, this);
broadcastManager = LocalBroadcastManager.getInstance(appContext);
noisyAudioStreamReceiver = new NoisyAudioStreamReceiver();
registerReceiver(noisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
ComponentName receiver = new ComponentName(this, MediaButtonReceiver.class);
mediaSession = new MediaSessionCompat(appContext, "QuranMediaSession", receiver, null);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setCallback(new MediaSessionCallback());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setupNotificationChannel();
}
notificationColor = ContextCompat.getColor(this, R.color.audio_notification_color);
try {
// for Android Wear, use a 1x1 Bitmap with the notification color
displayIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(displayIcon);
canvas.drawColor(notificationColor);
} catch (OutOfMemoryError oom) {
Crashlytics.logException(oom);
}
}
use of android.support.v4.media.session.MediaSessionCompat in project android-app by LISTEN-moe.
the class AutoMediaBrowserService method setSessionToken.
private void setSessionToken() {
final MediaSessionCompat mediaSession = App.getService().getMediaSession();
setSessionToken(mediaSession.getSessionToken());
}
use of android.support.v4.media.session.MediaSessionCompat in project Phonograph by kabouzeid.
the class MusicService method setupMediaSession.
private void setupMediaSession() {
ComponentName mediaButtonReceiverComponentName = new ComponentName(getApplicationContext(), MediaButtonIntentReceiver.class);
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mediaButtonReceiverComponentName);
PendingIntent mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
mediaSession = new MediaSessionCompat(this, "Phonograph", mediaButtonReceiverComponentName, mediaButtonReceiverPendingIntent);
mediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
play();
}
@Override
public void onPause() {
pause();
}
@Override
public void onSkipToNext() {
playNextSong(true);
}
@Override
public void onSkipToPrevious() {
back(true);
}
@Override
public void onStop() {
quit();
}
@Override
public void onSeekTo(long pos) {
seek((int) pos);
}
@Override
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
return MediaButtonIntentReceiver.handleIntent(MusicService.this, mediaButtonEvent);
}
});
mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
mediaSession.setMediaButtonReceiver(mediaButtonReceiverPendingIntent);
}
use of android.support.v4.media.session.MediaSessionCompat in project butter-android by butterproject.
the class AbsPlayerFragment method onCreate.
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
mediaSession = new MediaSessionCompat(getContext(), BuildConfig.APPLICATION_ID);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setMediaButtonReceiver(null);
mediaSession.setCallback(new PlayerSessionCallback());
stateBuilder = new PlaybackStateCompat.Builder().setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SEEK_TO).addCustomAction(ACTION_SCALE, getString(R.string.scale), R.drawable.ic_av_aspect_ratio);
metadataBuilder = new MediaMetadataCompat.Builder();
}
Aggregations