Removing unnecessary playback logs
This commit is contained in:
-2
@@ -50,7 +50,6 @@ object BackgroundMedia {
|
||||
|
||||
fun removeBackgroundControllerAndReleaseIt() {
|
||||
bgInstance.value?.let {
|
||||
println("AABBCCDD removeBackgroundControllerAndReleaseIt")
|
||||
removeController(it)
|
||||
bgInstance.tryEmit(null)
|
||||
}
|
||||
@@ -58,7 +57,6 @@ object BackgroundMedia {
|
||||
|
||||
fun removeBackgroundControllerIfNotComposed() {
|
||||
bgInstance.value?.let {
|
||||
println("AABBCCDD removeBackgroundControllerIfNotComposed ${it.composed.value}")
|
||||
if (!it.composed.value) {
|
||||
removeController(it)
|
||||
}
|
||||
|
||||
+1
-5
@@ -57,7 +57,6 @@ fun GetVideoController(
|
||||
|
||||
// Prepares a VideoPlayer from the foreground service.
|
||||
DisposableEffect(key1 = videoUri) {
|
||||
println("AABBCC On DisposableEffect: ${controllerId.id} ${controllerId.controller.value}")
|
||||
// If it is not null, the user might have come back from a playing video, like clicking on
|
||||
// the notification of the video player.
|
||||
if (controllerId.needsController()) {
|
||||
@@ -152,7 +151,6 @@ fun GetVideoController(
|
||||
}
|
||||
|
||||
onDispose {
|
||||
println("AABBCC On Dispose: ${controllerId.id} ${controllerId.controller.value}")
|
||||
controllerId.composed.value = false
|
||||
if (!controllerId.keepPlaying.value) {
|
||||
PlaybackServiceClient.removeController(controllerId)
|
||||
@@ -167,13 +165,12 @@ fun GetVideoController(
|
||||
LifecycleEventObserver { _, event ->
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
controllerId.composed.value = true
|
||||
println("AABBCC On Resume: ${controllerId.id} ${controllerId.controller.value}")
|
||||
// if the controller is null, restarts the controller with a new one
|
||||
// if the controller is not null, just continue playing what the controller was playing
|
||||
if (controllerId.controller.value == null) {
|
||||
if (!onlyOnePreparing.getAndSet(true)) {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
Log.d("PlaybackService", "AABBCC Preparing Video from Resume ${controllerId.id} $videoUri ")
|
||||
Log.d("PlaybackService", "Preparing Video from Resume ${controllerId.id} $videoUri ")
|
||||
PlaybackServiceClient.prepareController(
|
||||
controllerId,
|
||||
videoUri,
|
||||
@@ -228,7 +225,6 @@ fun GetVideoController(
|
||||
}
|
||||
if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
controllerId.composed.value = false
|
||||
println("AABBCC On Pause: ${controllerId.keepPlaying.value} ${controllerId.id}")
|
||||
if (!controllerId.keepPlaying.value) {
|
||||
// Stops and releases the media.
|
||||
PlaybackServiceClient.removeController(controllerId)
|
||||
|
||||
+2
-14
@@ -21,6 +21,7 @@
|
||||
package com.vitorpamplona.amethyst.service.playback.playerPool
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.util.LruCache
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.media3.common.MediaItem
|
||||
@@ -82,7 +83,6 @@ class MediaSessionPool(
|
||||
id: String,
|
||||
context: Context,
|
||||
): MediaSession {
|
||||
println("AABBCC New Session. Cache has ${cache.size()} sessions. Playing ${playingMap.size}")
|
||||
val mediaSession =
|
||||
MediaSession
|
||||
.Builder(context, exoPlayerPool.acquirePlayer(context))
|
||||
@@ -103,12 +103,9 @@ class MediaSessionPool(
|
||||
}
|
||||
|
||||
fun releaseSession(session: MediaSession) {
|
||||
println("AABBCC Release Session ${session.id}. Cache has ${cache.size()} sessions. Playing ${playingMap.size}")
|
||||
val listener = playingMap.get(session.id) ?: cache.get(session.id)
|
||||
if (listener != null) {
|
||||
session.player.removeListener(listener.playerListener)
|
||||
} else {
|
||||
println("AABBCC ERROR listener not found")
|
||||
}
|
||||
|
||||
cache.remove(session.id)
|
||||
@@ -129,18 +126,13 @@ class MediaSessionPool(
|
||||
// but not connected yet.
|
||||
// delay(10000)
|
||||
snap.values.forEach {
|
||||
println("AABBCC CleanUpUnused ${it.session.connectedControllers.size} ${it.session.id}")
|
||||
it.session.connectedControllers.forEach { conn ->
|
||||
println("AABBCC CleanUpUnused ${conn.connectionHints.keySet().joinToString(", ") { "$it " + conn.connectionHints.get(it).toString() }}")
|
||||
}
|
||||
Log.d("MediaSessionPoll", "Clean Up Unused ${it.session.connectedControllers.size} ${it.session.id}")
|
||||
if (it.session.connectedControllers.isEmpty()) {
|
||||
releaseSession(it.session)
|
||||
counter++
|
||||
}
|
||||
}
|
||||
lastCleanup = TimeUtils.now()
|
||||
|
||||
println("AABBCC Launched Cleanup: $counter sessions released")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +157,6 @@ class MediaSessionPool(
|
||||
): MediaSession {
|
||||
val existingSession = playingMap.get(id) ?: cache.get(id)
|
||||
if (existingSession != null) {
|
||||
println("AABBCC Reusing session $id")
|
||||
return existingSession.session
|
||||
}
|
||||
|
||||
@@ -183,7 +174,6 @@ class MediaSessionPool(
|
||||
controller: MediaSession.ControllerInfo,
|
||||
mediaItems: List<MediaItem>,
|
||||
): ListenableFuture<List<MediaItem>> {
|
||||
println("AABBCC onAddMediaItems ${mediaSession.id}")
|
||||
mediaSession.player.setMediaItems(mediaItems)
|
||||
|
||||
// set up return call when clicking on the Notification bar
|
||||
@@ -198,7 +188,6 @@ class MediaSessionPool(
|
||||
session: MediaSession,
|
||||
controller: MediaSession.ControllerInfo,
|
||||
) {
|
||||
println("AABBCC OnDisconnected ${session.connectedControllers.size} ${session.id}")
|
||||
pool.releaseSession(session)
|
||||
}
|
||||
}
|
||||
@@ -208,7 +197,6 @@ class MediaSessionPool(
|
||||
val pool: MediaSessionPool,
|
||||
) : Player.Listener {
|
||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||
println("AABBCC onIsPlayingChanged ${mediaSession.id} isPlaying $isPlaying")
|
||||
if (isPlaying) {
|
||||
pool.playingMap.put(mediaSession.id, SessionListener(mediaSession, this))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user