Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/ Minor Android code improvement in MediaPlaybackService #330

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('coroutinesVersion', '1.7.3')}"
implementation "androidx.appcompat:appcompat:${safeExtGet('appcompatVersion', '1.6.1')}"
implementation "androidx.core:core-ktx:${safeExtGet('corektxVersion', '1.10.1')}"
implementation "androidx.core:core-ktx:${safeExtGet('corektxVersion', '1.12.0')}"

// The minimum supported THEOplayer version is 7.12.0
def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[7.12.0, 8.0.0)')
Expand Down
18 changes: 7 additions & 11 deletions android/src/main/java/com/theoplayer/media/MediaPlaybackService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,14 @@ class MediaPlaybackService : Service() {

private fun startForegroundWithPlaybackState(@PlaybackStateCompat.State playbackState: Int, largeIcon: Bitmap? = null) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
NOTIFICATION_ID,
notificationBuilder.build(playbackState, largeIcon, mediaSessionConfig.mediaSessionEnabled),
ServiceCompat.startForeground(
this,
NOTIFICATION_ID,
notificationBuilder.build(playbackState, largeIcon, mediaSessionConfig.mediaSessionEnabled),
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
)
} else {
startForeground(
NOTIFICATION_ID,
notificationBuilder.build(playbackState, largeIcon, mediaSessionConfig.mediaSessionEnabled)
)
}
else 0
)
} catch (e: IllegalStateException) {
// Make sure that app does not crash in case anything goes wrong with starting the service.
// https://issuetracker.google.com/issues/229000935
Expand Down
Loading