Skip to content

Commit b99b19e

Browse files
fix(player): catch exceptions from PlaylistManager
1 parent d42d626 commit b99b19e

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

app/phone/src/main/java/dev/jdtech/jellyfin/utils/PlayerGestureHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class PlayerGestureHelper(
166166
}
167167
}
168168
in rightmostAreaStart until viewWidth -> {
169-
if (activity.viewModel.isLastChapter() == true) {
169+
if (activity.viewModel.isLastChapter()) {
170170
playerView.player?.seekToNextMediaItem()
171171
return
172172
}

player/local/src/main/java/dev/jdtech/jellyfin/player/local/presentation/PlayerViewModel.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.jdtech.jellyfin.player.local.presentation
33
import android.app.Application
44
import android.graphics.Bitmap
55
import android.graphics.BitmapFactory
6+
import android.widget.Toast
67
import androidx.lifecycle.SavedStateHandle
78
import androidx.lifecycle.ViewModel
89
import androidx.lifecycle.viewModelScope
@@ -171,12 +172,23 @@ constructor(
171172

172173
viewModelScope.launch {
173174
val startItem =
174-
playlistManager.getInitialItem(
175-
itemId = itemId,
176-
itemKind = BaseItemKind.fromName(itemKind),
177-
mediaSourceIndex = null,
178-
startFromBeginning = startFromBeginning,
179-
)
175+
try {
176+
playlistManager.getInitialItem(
177+
itemId = itemId,
178+
itemKind = BaseItemKind.fromName(itemKind),
179+
mediaSourceIndex = null,
180+
startFromBeginning = startFromBeginning,
181+
)
182+
} catch (e: Exception) {
183+
Timber.e(e)
184+
Toast.makeText(application, e.localizedMessage, Toast.LENGTH_LONG).show()
185+
null
186+
}
187+
188+
if (startItem == null) {
189+
Timber.e("No start item, stopping player initialization")
190+
return@launch
191+
}
180192

181193
items = listOfNotNull(startItem).toMutableList()
182194
currentMediaItemIndex = items.indexOf(startItem)
@@ -236,11 +248,14 @@ constructor(
236248
GlobalScope.launch {
237249
delay(200L)
238250
try {
239-
repository.postPlaybackStop(
240-
UUID.fromString(mediaId),
241-
position.times(10000),
242-
position.div(duration.toFloat()).times(100).toInt(),
243-
)
251+
if (mediaId != null && duration != C.TIME_UNSET) {
252+
Timber.d("Sending playback stop")
253+
repository.postPlaybackStop(
254+
UUID.fromString(mediaId),
255+
position.times(10000),
256+
position.div(duration.toFloat()).times(100).toInt(),
257+
)
258+
}
244259
} catch (e: Exception) {
245260
Timber.e(e)
246261
}
@@ -616,7 +631,7 @@ constructor(
616631
return maxOf(0, currentChapterIndex - 1)
617632
}
618633

619-
fun isLastChapter(): Boolean? =
634+
fun isLastChapter(): Boolean =
620635
getChapters().let { chapters -> getCurrentChapterIndex() == chapters.size - 1 }
621636

622637
/**

0 commit comments

Comments
 (0)