Fixed loop and autoplay while casting.

This commit is contained in:
Koen J
2025-11-21 10:05:33 +01:00
parent 0be0dcfadc
commit cbf3db6e30
4 changed files with 52 additions and 2 deletions
@@ -719,6 +719,7 @@ class VideoDetailView : ConstraintLayout {
val v = video;
if (!it && v != null && v.duration - activeDevice.time.toLong() < 2L) {
Log.i(TAG, "Next video (loop?)")
nextVideo();
}
}
@@ -1344,7 +1345,22 @@ class VideoDetailView : ConstraintLayout {
return;
//Loop workaround
if(bypassSameVideoCheck && this.video?.url == video.url && StatePlayer.instance.loopVideo) {
_player.seekTo(0);
Log.i(TAG, "Loop")
if (_isCasting) {
Log.i(TAG, "Loop casting")
StateCasting.instance.activeDevice?.seekTo(0.0)
fragment.lifecycleScope.launch(Dispatchers.IO) {
try {
delay(300)
StateCasting.instance.activeDevice?.resumePlayback()
} catch (e: Throwable) {
Log.e(TAG, "Failed to resume", e)
}
}
} else {
Log.i(TAG, "Loop player")
_player.seekTo(0);
}
return;
}
@@ -1372,6 +1388,7 @@ class VideoDetailView : ConstraintLayout {
_minimize_title.text = video.name;
_minimize_meta.text = video.author.name;
StatePlayer.instance.setCurrentlyPlaying(video);
Log.i(TAG, "setCurrentlyPlaying (setVideoOverview) ${video.url} (${video.name})")
val subTitleSegments : ArrayList<String> = ArrayList();
if(video.viewCount > 0)
@@ -1809,6 +1826,7 @@ class VideoDetailView : ConstraintLayout {
}
StatePlayer.instance.startOrUpdateMediaSession(context, video);
Log.i(TAG, "setCurrentlyPlaying (nextVideo) ${video.url} (${video.name})")
StatePlayer.instance.setCurrentlyPlaying(video);
_liveChat?.stop();
@@ -2309,6 +2327,8 @@ class VideoDetailView : ConstraintLayout {
checkAndRemoveWatchLater();
var next = StatePlayer.instance.nextQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9, bypassVideoLoop);
Log.i(TAG, "next queue item ${next?.url} (${next?.name})")
val autoplayVideo = _autoplayVideo
if (next == null && autoplayVideo != null && StatePlayer.instance.autoplay) {
Logger.i(TAG, "Found autoplay video!")
@@ -2321,11 +2341,14 @@ class VideoDetailView : ConstraintLayout {
if(next == null && forceLoop)
next = StatePlayer.instance.restartQueue();
if(next != null) {
Logger.i(TAG, "Set video overview (next = ${next.url} (${next.name}))")
setVideoOverview(next, true, 0, true);
return true;
}
else
else {
Log.i(TAG, "setCurrentlyPlaying (nextVideo) null")
StatePlayer.instance.setCurrentlyPlaying(null);
}
return false;
}
@@ -125,6 +125,7 @@ class StatePlayer {
}
fun setCurrentlyPlaying(video: IPlatformVideo?) {
Log.i(TAG, "setCurrentlyPlaying ${video?.url} (${video?.name})")
currentVideo = video;
}
@@ -135,6 +136,7 @@ class StatePlayer {
onPlayerOpened.emit();
}
fun setPlayerClosed() {
Log.i(TAG, "setCurrentlyPlaying (setPlayerClosed) null")
setCurrentlyPlaying(null);
isOpen = false;
clearQueue();
@@ -13,6 +13,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.OptIn
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.DefaultTimeBar
import androidx.media3.ui.TimeBar
@@ -43,6 +44,7 @@ class CastView : ConstraintLayout {
private val _buttonSettings: ImageButton;
private val _buttonLoop: ImageButton;
private val _buttonPlay: ImageButton;
private val _buttonAutoplay: ImageButton;
private val _buttonPrevious: ImageButton;
private val _buttonNext: ImageButton;
private val _buttonPause: ImageButton;
@@ -78,6 +80,7 @@ class CastView : ConstraintLayout {
_buttonMinimize = findViewById(R.id.button_minimize);
_buttonSettings = findViewById(R.id.button_settings);
_buttonLoop = findViewById(R.id.button_loop);
_buttonAutoplay = findViewById(R.id.button_autoplay);
_buttonPlay = findViewById(R.id.button_play);
_buttonPrevious = findViewById(R.id.button_previous);
_buttonNext = findViewById(R.id.button_next);
@@ -178,6 +181,17 @@ class CastView : ConstraintLayout {
updateNextPrevious();
_buttonPrevious.setOnClickListener { onPrevious.emit() };
_buttonNext.setOnClickListener { onNext.emit() };
_buttonAutoplay.setOnClickListener {
StatePlayer.instance.autoplay = !StatePlayer.instance.autoplay;
updateAutoplayButton()
}
updateAutoplayButton()
}
private fun updateAutoplayButton() {
_buttonAutoplay.setColorFilter(ContextCompat.getColor(context, if (StatePlayer.instance.autoplay) com.futo.futopay.R.color.primary else R.color.white))
_buttonAutoplay.setColorFilter(ContextCompat.getColor(context, if (StatePlayer.instance.autoplay) com.futo.futopay.R.color.primary else R.color.white))
}
private fun updateCurrentChapter(chaptPos: Long, isScrub: Boolean = false): Boolean {
+11
View File
@@ -47,6 +47,17 @@
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageButton
android:id="@+id/button_autoplay"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="@string/cd_button_autoplay"
android:scaleType="fitCenter"
android:clickable="true"
android:padding="12dp"
app:srcCompat="@drawable/autoplay_24px" />
<com.futo.platformplayer.views.casting.CastButton
android:id="@+id/button_cast"
android:layout_width="50dp"