mirror of
https://github.com/samsonjs/media.git
synced 2026-03-30 10:15:48 +00:00
Set notification foreground service behaviour starting with API 31
When the foreground service type is set to `mediaPlayiback` this shouldn't be required. However, some reports from users say that setting the foreground service behavor fixes some problems on some devices. Setting it explicitely with this change makes sure users don't have to do that workaround themselves. Issue: androidx/media#167 PiperOrigin-RevId: 557608577
This commit is contained in:
parent
74fa0ed6bf
commit
6bd3e53e8d
3 changed files with 16 additions and 0 deletions
|
|
@ -145,6 +145,9 @@ This release includes the following changes since
|
|||
* Effect:
|
||||
* Add `VideoFrameProcessor.queueInputBitmap(Bitmap, Iterator<Long>)`
|
||||
queuing bitmap input by timestamp.
|
||||
* Set the notifications foreground service behavior to
|
||||
`FOREGROUND_SERVICE_IMMEDIATE` in `DefaultMediaNotificationProvider`
|
||||
([#167](https://github.com/androidx/media/issues/167)).
|
||||
* UI:
|
||||
* Add a `Player.Listener` implementation for Wear OS devices that handles
|
||||
playback suppression due to
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ dependencies {
|
|||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
implementation 'androidx.collection:collection:' + androidxCollectionVersion
|
||||
implementation 'androidx.media:media:' + androidxMediaVersion
|
||||
implementation 'androidx.core:core:' + androidxCoreVersion
|
||||
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:' + okhttpVersion
|
||||
androidTestImplementation project(modulePrefix + 'test-utils')
|
||||
androidTestImplementation project(modulePrefix + 'test-data')
|
||||
|
|
|
|||
|
|
@ -371,6 +371,10 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||
.setShowWhen(displayElapsedTimeWithChronometer)
|
||||
.setUsesChronometer(displayElapsedTimeWithChronometer);
|
||||
|
||||
if (Util.SDK_INT >= 31) {
|
||||
Api31.setForegroundServiceBehavior(builder);
|
||||
}
|
||||
|
||||
Notification notification =
|
||||
builder
|
||||
.setContentIntent(mediaSession.getSessionActivity())
|
||||
|
|
@ -692,6 +696,14 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||
}
|
||||
}
|
||||
|
||||
@RequiresApi(31)
|
||||
private static class Api31 {
|
||||
@DoNotInline
|
||||
public static void setForegroundServiceBehavior(NotificationCompat.Builder builder) {
|
||||
builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getBitmapLoadErrorMessage(Throwable throwable) {
|
||||
return "Failed to load bitmap: " + throwable.getMessage();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue