android-mediasession

How to get notification callbacks using Android MediaSessionCompat

て烟熏妆下的殇ゞ 提交于 2021-02-10 06:49:07
问题 I'm having some difficulty working with Android's MediaSession. I've been working on a prototype radio application that should stream from a url. So far I've got it working with a foreground service that gets controlled from a button in the home screen. The audio continues out width the app as expected however I have a notification that either shows a play or stop button depending on the playback state. My issue is that this button does not work. I've detected that onStartCommand is getting

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

可紊 提交于 2021-01-27 18:20:48
问题 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 even play and pause the audio from my Bluetooth headphones. All good. My challenge concerns the NotificationCompat.MediaStyle notification that appears on the lock screen and in the notifications tray. The notification appears properly. However,

Cannot resolve symbol 'MediaSessionCompat'

妖精的绣舞 提交于 2020-05-28 12:44:09
问题 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 kind of extra configuration to get this import, like in app build.gradle ? 回答1: Add these to your dependencies and sync Gradle: Pre-AndroidX implementation "com.android.support:support-compat:28.0.0" implementation "com.android.support:support

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

一个人想着一个人 提交于 2020-01-22 12:13:12
问题 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 callbacks. It seems like this is because the app that's playing audio created its own MediaSession and Android sends KeyEvents only to the newest MediaSession. To prevent this I create an OnActiveSessionsChangedListener and create a new MediaSession every

Android MediaSession not reacting to headphones

两盒软妹~` 提交于 2020-01-17 05:37:51
问题 I'm quite new to android and I'm creating a Music Player. I wasn't familiar with MediaSession and now I have a functioning Music Player but it does not support reacting to headphones clicks or pausing on incomming calls. This is my code: ComponentName mediaButtonReceiver = new ComponentName(context, MusicPlayerNotificationReceiver.class); final MediaSessionCompat mediaSession = new MediaSessionCompat(context, "Start MP", mediaButtonReceiver, null); mediaSession.setFlags(MediaSessionCompat

onAdjustVolume not called

浪子不回头ぞ 提交于 2019-12-24 10:37:01
问题 I am trying to get HARDWARE_HOOK button and volume change button in my service using MediaSession for Android 5.0+ . This has to work specially when screen is off/locked. The problem is that though I am able to receive HARDWARE_HOOK button event, the volume change is not detected. the onAdjustVolume method never gets called. import android.app.Service; import android.content.Intent; import android.media.MediaRouter; import android.media.session.MediaSession; import android.os.Binder; import

App crash on headset button click

◇◆丶佛笑我妖孽 提交于 2019-12-23 19:42:02
问题 I have build an audioplayer which is deployed in android google playstore. I'm using crashlytics to monitor crashes and ANRs. Recently I have been getting a lot of crashes MediaButtonReceiver. The headset clicks work fine in many devices. But some devices are giving this problem. Crashlytics report - Fatal Exception: java.lang.RuntimeException: Unable to start receiver android.support.v4.media.session.MediaButtonReceiver: java.lang.IllegalStateException: Could not find any Service that

How do you use MediaControllerCompat to control the current player?

混江龙づ霸主 提交于 2019-12-22 04:32:23
问题 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 MediaControllerCompat class when I don't have a token or MediaSessionCompat to instantiate it with? I am hoping to get some example code. 回答1: I asked Ian Lake, the Google dev who did the video on MediaSessionCompat, who said it is not possible

How to use MediaSession.setMediaButtonReceiver(PendingIntent) to resume playback

て烟熏妆下的殇ゞ 提交于 2019-12-12 18:15:12
问题 I'm trying to be able to start music playback from my app when the headset buttons are clicked while my app is stopped. I can use MediaSession.Callback onMediaButtonEvent() or the now deprecated registerMediaButtonEventReceiver() to listen for media button click WHILE my app is playing music, but if I pause the music for a minute, with my Activity and playback Service still running, and then I press the headset button, I see that I have lost the ability to receive the media button broadcast.

Why MediaSession not changing the lock screen background (may be Bitmap size problem: read for more info)?

南笙酒味 提交于 2019-12-11 10:38:34
问题 I am stuck in this problem from last 6 days after deep research through media session I found this important line Album artwork for display on the lock screen. The image is a bitmap with a maximum size of 320x320dp (if larger, it's scaled down). Now, Here is my code of media session and Notification... MEDIA SESSION @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void initMediaSession() { if (mediaSessionManager != null) return; mediaSessionManager = (android.media.session