Skip to content

Commit ffc4a04

Browse files
committed
fix: switching from online video to offline video (or vice-versa) doesn't work
1 parent 2116c64 commit ffc4a04

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ object NavigationHelper {
7474
val activity = ContextHelper.unwrapActivity<AbstractPlayerHostActivity>(context)
7575
val attachedToRunningPlayer = activity.runOnPlayerFragment {
7676
try {
77+
if (this.isOffline != isOffline) return@runOnPlayerFragment false
78+
7779
PlayingQueue.clearAfterCurrent()
7880
this.playNextVideo(videoId.toID())
7981

@@ -95,6 +97,8 @@ object NavigationHelper {
9597

9698
val audioOnlyMode = PreferenceHelper.getBoolean(PreferenceKeys.AUDIO_ONLY_MODE, false)
9799
val attachedToRunningAudioPlayer = activity.runOnAudioPlayerFragment {
100+
if (this.isOffline != isOffline) return@runOnAudioPlayerFragment false
101+
98102
PlayingQueue.clearAfterCurrent()
99103
this.playNextVideo(videoId.toID())
100104

app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class AudioPlayerFragment : Fragment(R.layout.fragment_audio_player), AudioPlaye
8282
private var handler = Handler(Looper.getMainLooper())
8383
private var isPaused = !PlayerHelper.playAutomatically
8484

85-
private var isOffline: Boolean = false
85+
var isOffline: Boolean = false
86+
private set
8687
private var playerController: MediaController? = null
8788

8889
override fun onCreate(savedInstanceState: Bundle?) {

app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ class PlayerFragment : Fragment(R.layout.fragment_player), CustomPlayerCallback
137137
private lateinit var videoId: String
138138
private var playlistId: String? = null
139139
private var channelId: String? = null
140-
private var isOffline: Boolean = false
140+
var isOffline: Boolean = false
141+
private set
141142

142143
// data and objects stored for the player
143144
private lateinit var streams: Streams
144-
val isShort: Boolean
145+
private val isShort: Boolean
145146
get() {
146147
if (PlayingQueue.getCurrent()?.isShort == true) return true
147148
if (!::playerController.isInitialized) return false
@@ -1106,6 +1107,9 @@ class PlayerFragment : Fragment(R.layout.fragment_player), CustomPlayerCallback
11061107

11071108
/**
11081109
* Manually skip to another video.
1110+
*
1111+
* You many only call this if the video is of the same type as the type of the currently running
1112+
* video, i.e. either both are online or both are offline.
11091113
*/
11101114
fun playNextVideo(nextId: String) {
11111115
playerController.sendCustomCommand(

0 commit comments

Comments
 (0)