release media controller

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parneet-guraya 2024-09-04 04:23:25 +05:30
parent e75ccb328f
commit 8e2525e0e6
No known key found for this signature in database
GPG key ID: 63B807C4B2A9064B

View file

@ -54,6 +54,7 @@ import androidx.media3.session.SessionToken
import androidx.media3.ui.DefaultTimeBar
import androidx.media3.ui.PlayerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors
import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager
@ -136,6 +137,7 @@ class PreviewMediaActivity :
private var videoPlayer: ExoPlayer? = null
private var videoMediaSession: MediaSession? = null
private var audioMediaController: MediaController? = null
private var mediaControllerFuture: ListenableFuture<MediaController>? = null
private var nextcloudClient: NextcloudClient? = null
private lateinit var windowInsetsController: WindowInsetsControllerCompat
@ -376,11 +378,11 @@ class PreviewMediaActivity :
private fun initializeAudioPlayer() {
val sessionToken = SessionToken(this, ComponentName(this, BackgroundPlayerService::class.java))
val controllerFuture = MediaController.Builder(this, sessionToken).buildAsync()
controllerFuture.addListener(
mediaControllerFuture = MediaController.Builder(this, sessionToken).buildAsync()
mediaControllerFuture?.addListener(
{
try {
audioMediaController = controllerFuture.get()
audioMediaController = mediaControllerFuture?.get()
playAudio()
binding.audioControllerView.setMediaPlayer(audioMediaController)
} catch (e: Exception) {
@ -768,6 +770,7 @@ class PreviewMediaActivity :
}
override fun onDestroy() {
mediaControllerFuture?.let {MediaController.releaseFuture(it)}
super.onDestroy()
Log_OC.v(TAG, "onDestroy")