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