mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +05:30
Fix various crashes caused by the player binding
This commit is contained in:
parent
72dc5ce7d1
commit
50a7acb5d7
@ -295,6 +295,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
endId: Int,
|
endId: Int,
|
||||||
progress: Float
|
progress: Float
|
||||||
) {
|
) {
|
||||||
|
if (_binding == null) return
|
||||||
|
|
||||||
mainMotionLayout.progress = abs(progress)
|
mainMotionLayout.progress = abs(progress)
|
||||||
binding.player.hideController()
|
binding.player.hideController()
|
||||||
binding.player.useController = false
|
binding.player.useController = false
|
||||||
@ -303,6 +305,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
||||||
|
if (_binding == null) return
|
||||||
|
|
||||||
if (currentId == eId) {
|
if (currentId == eId) {
|
||||||
viewModel.isMiniPlayerVisible.value = true
|
viewModel.isMiniPlayerVisible.value = true
|
||||||
// disable captions
|
// disable captions
|
||||||
@ -662,13 +666,17 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
streams = try {
|
streams = try {
|
||||||
RetrofitInstance.api.getStreams(videoId!!)
|
RetrofitInstance.api.getStreams(videoId!!)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_LONG).show()
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
return@launch
|
return@launch
|
||||||
} catch (e: HttpException) {
|
} catch (e: HttpException) {
|
||||||
val errorMessage = e.response()?.errorBody()?.string()?.runCatching {
|
val errorMessage = e.response()?.errorBody()?.string()?.runCatching {
|
||||||
JsonHelper.json.decodeFromString<Message>(this).message
|
JsonHelper.json.decodeFromString<Message>(this).message
|
||||||
}?.getOrNull() ?: context?.getString(R.string.server_error) ?: ""
|
}?.getOrNull() ?: context?.getString(R.string.server_error) ?: ""
|
||||||
Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show()
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1200,7 +1208,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
// set the name of the video chapter in the exoPlayerView
|
// set the name of the video chapter in the exoPlayerView
|
||||||
private fun setCurrentChapterName() {
|
private fun setCurrentChapterName() {
|
||||||
// return if chapters are empty to avoid crashes
|
// return if chapters are empty to avoid crashes
|
||||||
if (chapters.isEmpty()) return
|
if (chapters.isEmpty() || _binding == null) return
|
||||||
|
|
||||||
// call the function again in 100ms
|
// call the function again in 100ms
|
||||||
binding.player.postDelayed(this::setCurrentChapterName, 100)
|
binding.player.postDelayed(this::setCurrentChapterName, 100)
|
||||||
|
Loading…
Reference in New Issue
Block a user