Background playback fixes for limited version and artwork now shows while in background playback.

This commit is contained in:
Koen J
2025-07-21 15:43:43 +02:00
parent 5e5fffbf97
commit 2aef2ebec1
3 changed files with 47 additions and 6 deletions
@@ -719,7 +719,7 @@ class VideoDetailView : ConstraintLayout {
};
MediaControlReceiver.onBackgroundReceived.subscribe(this) {
Logger.i(TAG, "MediaControlReceiver.onBackgroundReceived")
_player.switchToAudioMode();
_player.switchToAudioMode(video);
allowBackground = true;
StateApp.instance.contextOrNull?.let {
try {
@@ -966,7 +966,7 @@ class VideoDetailView : ConstraintLayout {
} else null,
if (!isLimitedVersion) RoundButton(context, R.drawable.ic_screen_share, if (allowBackground) context.getString(R.string.background_revert) else context.getString(R.string.background), TAG_BACKGROUND) {
if (!allowBackground) {
_player.switchToAudioMode();
_player.switchToAudioMode(video);
allowBackground = true;
it.text.text = resources.getString(R.string.background_revert);
} else {
@@ -1137,7 +1137,7 @@ class VideoDetailView : ConstraintLayout {
0 -> handlePause();
1 -> {
if(!(video?.isLive ?: false))
_player.switchToAudioMode();
_player.switchToAudioMode(video);
StatePlayer.instance.startOrUpdateMediaSession(context, video);
}
}
@@ -1872,7 +1872,7 @@ class VideoDetailView : ConstraintLayout {
setCastEnabled(false);
val thumbnail = video.thumbnails.getHQThumbnail();
if (videoSource == null && !thumbnail.isNullOrBlank())
if ((videoSource == null || _player.isAudioMode) && !thumbnail.isNullOrBlank())
Glide.with(context).asBitmap().load(thumbnail)
.into(object: CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
@@ -4,7 +4,9 @@ import android.animation.ValueAnimator
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.media.AudioManager
import android.net.Uri
@@ -29,6 +31,9 @@ import androidx.media3.ui.AspectRatioFrameLayout
import androidx.media3.ui.PlayerControlView
import androidx.media3.ui.PlayerView
import androidx.media3.ui.TimeBar
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.futo.platformplayer.R
import com.futo.platformplayer.Settings
import com.futo.platformplayer.UIDialogs
@@ -36,6 +41,7 @@ import com.futo.platformplayer.api.media.models.chapters.ChapterType
import com.futo.platformplayer.api.media.models.chapters.IChapter
import com.futo.platformplayer.api.media.models.streams.sources.IAudioSource
import com.futo.platformplayer.api.media.models.streams.sources.IVideoSource
import com.futo.platformplayer.api.media.models.video.IPlatformVideoDetails
import com.futo.platformplayer.constructs.Event0
import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.constructs.Event2
@@ -890,4 +896,29 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
_loaderGame.visibility = View.VISIBLE
_loaderGame.startLoader(expectedDurationMs.toLong())
}
override fun switchToVideoMode() {
super.switchToVideoMode()
setArtwork(null)
}
override fun switchToAudioMode(video: IPlatformVideoDetails?) {
super.switchToAudioMode(video)
val thumbnail = video?.thumbnails?.getHQThumbnail()
if (!thumbnail.isNullOrBlank()) {
Glide.with(context).asBitmap().load(thumbnail)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(
resource: Bitmap,
transition: Transition<in Bitmap>?
) {
setArtwork(BitmapDrawable(resources, resource));
}
override fun onLoadCleared(placeholder: Drawable?) {
setArtwork(null);
}
})
}
}
}
@@ -1,6 +1,9 @@
package com.futo.platformplayer.views.video
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.AttributeSet
import android.view.LayoutInflater
@@ -31,6 +34,10 @@ import androidx.media3.exoplayer.source.MergingMediaSource
import androidx.media3.exoplayer.source.ProgressiveMediaSource
import androidx.media3.exoplayer.source.SingleSampleMediaSource
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.futo.platformplayer.BuildConfig
import com.futo.platformplayer.Settings
import com.futo.platformplayer.UIDialogs
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
@@ -266,7 +273,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
StateApp.instance.onConnectionAvailable.remove(_referenceObject);
}
fun switchToVideoMode() {
open fun switchToVideoMode() {
Logger.i(TAG, "Switching to Video Mode");
isAudioMode = false;
val player = exoPlayer ?: return
@@ -276,7 +283,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, isAudioMode)
.build()
}
fun switchToAudioMode() {
open fun switchToAudioMode(video: IPlatformVideoDetails?) {
Logger.i(TAG, "Switching to Audio Mode");
isAudioMode = true;
val player = exoPlayer ?: return
@@ -908,6 +915,9 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
}
fun clear() {
if (BuildConfig.IS_PLAYSTORE_BUILD) {
switchToVideoMode()
}
exoPlayer?.player?.stop();
exoPlayer?.player?.clearMediaItems();
setLoading(false)