Questions tagged [android-mediasession]

Allows interaction with media controllers, volume keys, media buttons, and transport controls.

A MediaSession should be created when an app wants to publish media playback information or handle media keys. In general an app only needs one session for all playback, though multiple sessions can be created to provide finer grain controls of media.

Once a session is created the owner of the session may pass its session token to other processes to allow them to create a MediaController to interact with the session.

To receive commands, media keys, and other events a MediaSession.Callback must be set with setCallback(Callback) and setActive(true) must be called.

When an app is finished performing playback it must call release() to clean up the session and notify any controllers.

175 questions
24
votes
3 answers

Cannot resolve symbol 'MediaSessionCompat'

I cannot import MediaSessionCompat. The import statement for importing the whole android.support.v4.media library does not show up in the Android Studio "IntelliSense" and it cannot resolve the symbol for anything inside it. Do I have to make some…
Emil Walser
  • 615
  • 2
  • 7
  • 14
20
votes
1 answer

Couldn't expand RemoteViews: MediaSessionCompat and NotificationCompat.MediaStyle on HUAWEI devices

My app crashes when I try to display an Notification on my HUAWEI P8 lite device running Android 5.0.1 (it works fine on Nexus and Samsung devices). Most of my code is taken from the video Media playback the right way (Big Android BBQ 2015) by Ian…
13
votes
2 answers

App does not become the preferred MediaButtonReceiver when calling setActive(true) a second time

I have tried to implement media button control per Google's talk I set the receiver in manifest:
Steve M
  • 9,296
  • 11
  • 49
  • 98
12
votes
1 answer

Android Media3 Session & Controller - Playback not starting

I'm trying to implement the Android Media3 MediaSessionService and MediaController but for some reason the playback doesn't start. What am I doing wrong? I think I did everything exactly as described in Play media in the…
12
votes
1 answer

What is the purpose of onGetRoot() and onLoadChildren() in MediaBrowserServiceCompat?

I am a beginner in Android Development trying to create a media player with the implementation of MediaBrowser and MediaSession. I am confused with the function of onGetRoot() and onLoadChildren(). My first question is in layman's term what is the…
Player1
  • 2,878
  • 2
  • 26
  • 38
11
votes
2 answers

MediaMetadataCompat METADATA_KEY_ART only sets image the first time

In my application, I'm making use of MediaSessionCompat to handle playing audio from my media player service. Particularly, I want to broadcast the current song's metadata to bluetooth devices (which works), and set the lock screen image to the…
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
10
votes
0 answers

Youtube iframe api: interact with MediaSession

I have an angular app with the Youtube IFrame API. When the website/pwa is used on an android device, and a Youtube video is playing, the app automatically creates a notification in the android notification tray, allowing you to see what video is…
10
votes
3 answers

onMetadataChanged MediaControllerCompat.Callback never called

I'm developing a simple Audio Player app for a radio station. I have successfully made a MediaBrowser and registered a callback to listen for playBack- or metadata changes. var mediaBrowser : MediaBrowserCompat by Delegates.notNull() mediaBrowser =…
timr
  • 6,668
  • 7
  • 47
  • 79
9
votes
2 answers

Receive callback on all Android media button events all the time (even when another app is playing audio)

Background Info: I need to detect whenever a user presses the play/pause button found on most headsets (KEYCODE_MEDIA_PLAY_PAUSE). I have it all mostly working using MediaSessions, but when another app starts playing audio, I stop getting…
Mihai
  • 296
  • 2
  • 12
8
votes
2 answers

Adding MediaItem when using the media3 library caused an error

I am using the latest Android Media3 library, but I found a problem in using it... I created a MediaSessionService, and then got the MediaController in the Activity, and then when I tried to call the media controller and add some MediaItems, an…
RE_OVO
  • 93
  • 1
  • 6
8
votes
1 answer

MediaButtonReceiver not working with MediaBrowserServiceCompat

I am trying to receive media button events from headsets or car controls (play/pause/etc.) This is in my app manifest.
Hackmodford
  • 3,901
  • 4
  • 35
  • 78
8
votes
2 answers

How do you use MediaControllerCompat to control the current player?

My app is not the media player. I just want to be able to control the current media player using the new MediaControllerCompat class. Currently I am using MediaSessionManager but want to upgrade to the new compat classes. How do I instantiate the…
7
votes
3 answers

Catching android media button events

I have an app that launches a foreground service to play some media and I want to be able to control it with media buttons on smart watches/headphones and control it from a mediastyle notification etc. I cannot get the media buttons to work…
7
votes
2 answers

onSkipToNext() and onSkipToPrevious() of MediaSessionCompat.Callback does not get triggered

I'm trying to implement a notification player in Android. I followed this guide to achieve this. However as my requirement I need to implement "skip to next" and "skip to previous" in the background notification player. So far onPlay() and onPause()…
6
votes
1 answer

Android: NotificationCompat.MediaStyle action buttons don't do anything

I've got a simple Android app containing one Activity and a Service that derives from MediaBrowserServiceCompat. I've successfully gotten it set up to play audio from my main activity by using MediaBrowserCompat and MediaControllerCompat. It can…
1
2 3
11 12