mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
catch player errors
This commit is contained in:
parent
e888b8a061
commit
db1eb14436
@ -78,6 +78,7 @@ import com.google.android.exoplayer2.ExoPlayer
|
|||||||
import com.google.android.exoplayer2.MediaItem
|
import com.google.android.exoplayer2.MediaItem
|
||||||
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
|
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
|
||||||
import com.google.android.exoplayer2.MediaItem.fromUri
|
import com.google.android.exoplayer2.MediaItem.fromUri
|
||||||
|
import com.google.android.exoplayer2.PlaybackException
|
||||||
import com.google.android.exoplayer2.Player
|
import com.google.android.exoplayer2.Player
|
||||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||||
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
|
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
|
||||||
@ -971,22 +972,6 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onVideoSizeChanged(
|
|
||||||
videoSize: VideoSize
|
|
||||||
) {
|
|
||||||
// Set new width/height of view
|
|
||||||
// height or width must be cast to float as int/int will give 0
|
|
||||||
|
|
||||||
// Redraw the player container with the new layout height
|
|
||||||
val params = binding.player.layoutParams
|
|
||||||
params.height = videoSize.height / videoSize.width * params.width
|
|
||||||
binding.player.layoutParams = params
|
|
||||||
binding.player.requestLayout()
|
|
||||||
(binding.mainContainer.layoutParams as ConstraintLayout.LayoutParams).apply {
|
|
||||||
matchConstraintPercentHeight = (videoSize.height / videoSize.width).toFloat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
exoPlayerView.keepScreenOn = !(
|
exoPlayerView.keepScreenOn = !(
|
||||||
playbackState == Player.STATE_IDLE ||
|
playbackState == Player.STATE_IDLE ||
|
||||||
@ -1032,6 +1017,18 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
super.onPlaybackStateChanged(playbackState)
|
super.onPlaybackStateChanged(playbackState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catch player errors to prevent the app from stopping
|
||||||
|
*/
|
||||||
|
override fun onPlayerError(error: PlaybackException) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
error.localizedMessage,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
super.onPlayerError(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// check if livestream
|
// check if livestream
|
||||||
|
Loading…
Reference in New Issue
Block a user