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

Move media session implementation to exoplayer module #3670

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ dependencies {
implementation(projects.playback.core)
implementation(projects.playback.exoplayer)
implementation(projects.playback.jellyfin)
implementation(projects.playback.ui)
implementation(projects.preference)
implementation(libs.jellyfin.apiclient)
implementation(libs.jellyfin.sdk) {
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/org/jellyfin/androidtv/di/PlaybackModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import org.jellyfin.androidtv.ui.playback.MediaManager
import org.jellyfin.androidtv.ui.playback.RewritePlaybackLauncher
import org.jellyfin.androidtv.ui.playback.VideoQueueManager
import org.jellyfin.androidtv.ui.playback.rewrite.RewriteMediaManager
import org.jellyfin.playback.core.mediasession.MediaSessionOptions
import org.jellyfin.playback.core.mediasession.mediaSessionPlugin
import org.jellyfin.playback.core.playbackManager
import org.jellyfin.playback.exoplayer.exoPlayerPlugin
import org.jellyfin.playback.exoplayer.session.MediaSessionOptions
import org.jellyfin.playback.jellyfin.jellyfinPlugin
import org.koin.android.ext.koin.androidContext
import org.koin.core.scope.Scope
Expand All @@ -44,13 +43,10 @@ val playbackModule = module {
}

fun Scope.createPlaybackManager() = playbackManager(androidContext()) {
install(exoPlayerPlugin(get()))
install(jellyfinPlugin(get()))

val activityIntent = Intent(get(), MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(get(), 0, activityIntent, PendingIntent.FLAG_IMMUTABLE)

val notificationChannelId = "mediasession"
val notificationChannelId = "session"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
notificationChannelId,
Expand All @@ -60,12 +56,13 @@ fun Scope.createPlaybackManager() = playbackManager(androidContext()) {
NotificationManagerCompat.from(get()).createNotificationChannel(channel)
}

install(mediaSessionPlugin(get(), MediaSessionOptions(
val mediaSessionOptions = MediaSessionOptions(
channelId = notificationChannelId,
notificationId = 1,
iconSmall = R.drawable.app_icon_foreground,
openIntent = pendingIntent,
)))
openIntent = pendingIntent,)
install(exoPlayerPlugin(get(), mediaSessionOptions))
install(jellyfinPlugin(get()))

// Options
val userSettingPreferences = get<UserSettingPreferences>()
Expand Down
7 changes: 0 additions & 7 deletions playback/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id("com.android.library")
kotlin("android")
alias(libs.plugins.kotlin.serialization)
}

android {
Expand Down Expand Up @@ -29,15 +28,9 @@ android {
dependencies {
// Kotlin
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.guava)
implementation(libs.kotlinx.serialization.json)

// Android(x)
implementation(libs.androidx.core)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
implementation(libs.bundles.androidx.lifecycle)
implementation(libs.androidx.media3.session)

// Dependency Injection
implementation(libs.bundles.koin)
Expand Down
14 changes: 1 addition & 13 deletions playback/core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service
android:name="org.jellyfin.playback.core.mediasession.AndroidMediaService"
android:exported="true"
android:foregroundServiceType="mediaPlayback">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService" />
</intent-filter>
</service>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ internal class MediaStreamState(
}
}
}.launchIn(coroutineScope + Dispatchers.Main)

// TODO Register some kind of event when $current item is at -30 seconds to setNext()
}

Expand Down
6 changes: 5 additions & 1 deletion playback/exoplayer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ dependencies {
// AndroidX
implementation(libs.androidx.core)

// ExoPlayer
// media3
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.exoplayer.hls)
implementation(libs.jellyfin.androidx.media3.ffmpeg.decoder)
implementation(libs.androidx.media3.ui)
implementation(libs.androidx.media3.session)

// Logging
implementation(libs.timber)

// Compatibility (desugaring)
coreLibraryDesugaring(libs.android.desugar)

// Testing
testImplementation(libs.kotest.runner.junit5)
testImplementation(libs.kotest.assertions)
Expand Down
16 changes: 15 additions & 1 deletion playback/exoplayer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<service
android:name="org.jellyfin.playback.exoplayer.session.AndroidMediaService"
android:exported="true"
android:foregroundServiceType="mediaPlayback"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService" />
</intent-filter>
</service>
</application>
</manifest>
8 changes: 7 additions & 1 deletion playback/exoplayer/src/main/kotlin/ExoPlayerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package org.jellyfin.playback.exoplayer

import android.content.Context
import org.jellyfin.playback.core.plugin.playbackPlugin
import org.jellyfin.playback.exoplayer.session.MediaSessionOptions
import org.jellyfin.playback.exoplayer.session.MediaSessionService

fun exoPlayerPlugin(androidContext: Context) = playbackPlugin {
fun exoPlayerPlugin(
androidContext: Context,
mediaSessionOptions: MediaSessionOptions,
) = playbackPlugin {
provide(ExoPlayerBackend(androidContext))
provide(MediaSessionService(androidContext, mediaSessionOptions))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jellyfin.playback.core.mediasession
package org.jellyfin.playback.exoplayer.session

import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jellyfin.playback.core.mediasession
package org.jellyfin.playback.exoplayer.session

import android.app.PendingIntent
import androidx.annotation.DrawableRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jellyfin.playback.core.mediasession
package org.jellyfin.playback.exoplayer.session

import android.os.Looper
import androidx.annotation.OptIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jellyfin.playback.core.mediasession
package org.jellyfin.playback.exoplayer.session

import android.content.Context
import android.os.Looper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jellyfin.playback.core.mediasession
package org.jellyfin.playback.exoplayer.session

import androidx.core.net.toUri
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import org.jellyfin.playback.core.queue.QueueEntryMetadata

fun QueueEntryMetadata.toMediaItem() = MediaItem.Builder().apply {
if (mediaId != null) setMediaId(mediaId)
mediaId?.let { setMediaId(it) }

setMediaMetadata(MediaMetadata.Builder().apply {
setTitle(title)
Expand Down
59 changes: 0 additions & 59 deletions playback/ui/build.gradle.kts

This file was deleted.

6 changes: 0 additions & 6 deletions playback/ui/src/main/AndroidManifest.xml

This file was deleted.

1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ include(":app")
include(":playback:core")
include(":playback:exoplayer")
include(":playback:jellyfin")
include(":playback:ui")
include(":preference")

pluginManagement {
Expand Down
Loading