Tabnine Logo
android.media.session
Code IndexAdd Tabnine to your IDE (free)

How to use android.media.session

Best Java code snippets using android.media.session (Showing top 20 results out of 315)

origin: naman14/Timber

@Override
public void onDestroy() {
  mServiceStarted = false;
  mSession.release();
}
origin: aa112901/remusic

private void setUpMediaSession() {
  mSession = new MediaSession(this, "remusic");
  mSession.setCallback(new MediaSession.Callback() {
    @Override
    public void onPause() {
  mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
origin: naman14/Timber

private void setSessionInactive() {
  if (mServiceStarted) {
    stopSelf();
    mServiceStarted = false;
  }
  if (mSession.isActive()) {
    mSession.setActive(false);
  }
}
origin: stackoverflow.com

final MediaSession mediaSession = new MediaSession(this, "debug tag");
mediaSession.setMetadata(new MediaMetadata.Builder()
    .putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, artwork)
    .putString(MediaMetadata.METADATA_KEY_ARTIST, "Pink Floyd")
    .build());
mediaSession.setActive(true);
mediaSession.setCallback(new MediaSession.Callback() {
mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
        .setMediaSession(mediaSession.getSessionToken())
final TransportControls controls = mediaSession.getController().getTransportControls();
origin: naman14/Timber

@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);
}
origin: aa112901/remusic

mSession.setPlaybackState(new PlaybackState.Builder()
    .setState(playState, position(), 1.0f)
    .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE |
        PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
    .build());
mSession.setMetadata(new MediaMetadata.Builder()
    .putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName())
    .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName())
    .build());
mSession.setPlaybackState(new PlaybackState.Builder()
    .setState(playState, position(), 1.0f)
    .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE |
        PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
    .build());
origin: vanilla-music/vanilla

/**
 * Unregisters a registered media session
 */
public void unregisterRemote() {
  if (mMediaSession != null) {
    mMediaSession.setActive(false);
    mMediaSession.release();
    mMediaSession = null;
  }
}
origin: aa112901/remusic

private void releaseServiceUiAndStop() {
  if (isPlaying()
      || mPausedByTransientLossOfFocus
      || mPlayerHandler.hasMessages(TRACK_ENDED)) {
    return;
  }
  if (D) Log.d(TAG, "Nothing is playing anymore, releasing notification");
  cancelNotification();
  mAudioManager.abandonAudioFocus(mAudioFocusListener);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    mSession.setActive(false);
  if (!mServiceInUse) {
    saveQueue(true);
    stopSelf(mServiceStartId);
  }
}
origin: robolectric/robolectric

 @Test
 public void mediaSessionCompat_creation() throws Exception {
  // Should not result in an exception.
  new MediaSession(ApplicationProvider.getApplicationContext(), "test");
 }
}
origin: googlesamples/android-PictureInPicture

private void assertMediaStateIs(@PlaybackStateCompat.State int expectedState) {
  PlaybackState state = rule.getActivity().getMediaController().getPlaybackState();
  assertNotNull(state);
  assertThat(
      "MediaSession is not in the correct state",
      state.getState(),
      is(equalTo(expectedState)));
}
origin: stackoverflow.com

 PlaybackState state = new PlaybackState.Builder()
    .setActions(
        PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE |
        PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE |
        PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
    .setState(PlaybackState.STATE_PLAYING, position, speed, SystemClock.elapsedRealtime())
    .build();
mSession.setPlaybackState(state);
origin: KDE/kdeconnect-android

  long getPosition() {
    if (controller.getPlaybackState() == null)
      return 0;
    return controller.getPlaybackState().getPosition();
  }
}
origin: KDE/kdeconnect-android

void playPause() {
  if (isPlaying) {
    controller.getTransportControls().pause();
  } else {
    controller.getTransportControls().play();
  }
}
origin: KDE/kdeconnect-android

int getVolume() {
  if (controller.getPlaybackInfo() == null)
    return 0;
  return 100 * controller.getPlaybackInfo().getCurrentVolume() / controller.getPlaybackInfo().getMaxVolume();
}
origin: KDE/kdeconnect-android

void previous() {
  controller.getTransportControls().skipToPrevious();
}
origin: naman14/Timber

private void setSessionActive() {
  if (!mServiceStarted) {
    startService(new Intent(getApplicationContext(), WearBrowserService.class));
    mServiceStarted = true;
  }
  if (!mSession.isActive()) {
    mSession.setActive(true);
  }
}
origin: aa112901/remusic

@Override
public void onDestroy() {
  if (D) Log.d(TAG, "Destroying service");
  super.onDestroy();
  // Remove any sound effects
  final Intent audioEffectsIntent = new Intent(
      AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
  audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
  audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
  sendBroadcast(audioEffectsIntent);
  cancelNotification();
  mAlarmManager.cancel(mShutdownIntent);
  mPlayerHandler.removeCallbacksAndMessages(null);
  if (CommonUtils.isJellyBeanMR2())
    mHandlerThread.quitSafely();
  else mHandlerThread.quit();
  mPlayer.release();
  mPlayer = null;
  mAudioManager.abandonAudioFocus(mAudioFocusListener);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    mSession.release();
  getContentResolver().unregisterContentObserver(mMediaStoreObserver);
  closeCursor();
  unregisterReceiver(mIntentReceiver);
  if (mUnmountReceiver != null) {
    unregisterReceiver(mUnmountReceiver);
    mUnmountReceiver = null;
  }
  mWakeLock.release();
}
origin: aa112901/remusic

    MediaButtonIntentReceiver.class.getName()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
  mSession.setActive(true);
if (createNewNextTrack) {
  setNextTrack();
origin: KDE/kdeconnect-android

MprisReceiverPlayer(MediaController controller, String name) {
  this.controller = controller;
  this.name = name;
  if (controller.getPlaybackState() != null) {
    isPlaying = controller.getPlaybackState().getState() == PlaybackState.STATE_PLAYING;
  }
}
origin: stackoverflow.com

 PlaybackState state = new PlaybackState.Builder()
            .setActions(PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_STOP)
            .setState(PlaybackStateCompat.STATE_PLAYING, 0, 1, SystemClock.elapsedRealtime())
            .build();
mSession.setPlaybackState(state);
android.media.session

Most used classes

  • MediaSession
  • MediaController
  • PlaybackState$Builder
  • MediaSessionManager
  • PlaybackState
  • MediaController$TransportControls,
  • PlaybackState$CustomAction$Builder
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now