use of android.support.v4.media.session.MediaSessionCompat in project AndroidAudioExample by SergeyVinyar.
the class MediaStyleHelper method from.
/**
* Build a notification using the information from the given media session. Makes heavy use
* of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
*
* @param context Context used to construct the notification.
* @param mediaSession Media session to get information.
* @return A pre-built notification with information from the given media session.
*/
static NotificationCompat.Builder from(Context context, MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(description.getTitle()).setContentText(description.getSubtitle()).setSubText(description.getDescription()).setLargeIcon(description.getIconBitmap()).setContentIntent(controller.getSessionActivity()).setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
use of android.support.v4.media.session.MediaSessionCompat in project android-app by LISTEN-moe.
the class RadioService method initMediaSession.
private void initMediaSession() {
mediaSession = new MediaSessionCompat(this, APP_PACKAGE_NAME, null, null);
mediaSession.setRatingType(RatingCompat.RATING_HEART);
mediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
play();
}
@Override
public void onPause() {
pause();
}
@Override
public void onStop() {
stop();
}
@Override
public void onSkipToNext() {
}
@Override
public void onSkipToPrevious() {
}
@Override
public void onSeekTo(long pos) {
}
@Override
public void onSetRating(RatingCompat rating) {
favoriteCurrentSong();
}
@Override
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
return handleIntent(mediaButtonEvent);
}
@Override
public void onCustomAction(@NonNull String action, Bundle extras) {
switch(action) {
case TOGGLE_FAVORITE:
favoriteCurrentSong();
updateMediaSessionPlaybackState();
break;
default:
Log.d(TAG, "Unsupported action: " + action);
break;
}
}
@Override
public void onPlayFromSearch(String query, Bundle extras) {
// We don't support searching for specific things since it's just a radio stream
// so just toggle playback
togglePlayPause();
}
});
mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
mediaSession.setActive(true);
}
use of android.support.v4.media.session.MediaSessionCompat in project butter-android by butterproject.
the class TVAbsPlayerFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaSession = new MediaSessionCompat(requireContext(), 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();
metadataBuilder = new MediaMetadataCompat.Builder();
}
use of android.support.v4.media.session.MediaSessionCompat in project vialer-android by VoIPGRID.
the class BluetoothMediaSessionService method onCreate.
@Override
public void onCreate() {
mContext = this;
mRemoteLogger = new RemoteLogger(BluetoothMediaSessionService.class).enableConsoleLogging();
mRemoteLogger.v("onCreate()");
MediaSessionCompat session = new MediaSessionCompat(this, TAG);
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
stateBuilder.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS);
stateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, 0, 1);
session.setPlaybackState(stateBuilder.build());
session.setCallback(mSessionCallback);
session.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
session.setPlaybackToLocal(AudioManager.STREAM_VOICE_CALL);
mSession = session;
}
use of android.support.v4.media.session.MediaSessionCompat in project LibreraReader by foobnix.
the class TTSService method onCreate.
@Override
public void onCreate() {
LOG.d(TAG, "Create");
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TTSService");
AppState.get().load(getApplicationContext());
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(listener, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
mMediaSessionCompat = new MediaSessionCompat(getApplicationContext(), "Tag");
mMediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSessionCompat.setCallback(new MediaSessionCompat.Callback() {
@Override
public boolean onMediaButtonEvent(Intent intent) {
LOG.d(TAG, "onMediaButtonEvent", isActivated, intent);
if (isActivated) {
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
if (KeyEvent.ACTION_UP == event.getAction() && KeyEvent.KEYCODE_HEADSETHOOK == event.getKeyCode()) {
LOG.d(TAG, "onStartStop", "KEYCODE_HEADSETHOOK");
boolean isPlaying = TTSEngine.get().isPlaying();
if (isPlaying) {
TTSEngine.get().stop();
} else {
playPage("", AppState.get().lastBookPage, null);
}
}
}
return isActivated;
}
});
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
mMediaSessionCompat.setMediaButtonReceiver(pendingIntent);
TTSEngine.get().getTTS();
}
Aggregations