mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #2848 from Bnyro/master
Minor player view improvements
This commit is contained in:
commit
19e702d118
@ -184,6 +184,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
private var sponsorBlockEnabled = PlayerHelper.sponsorBlockEnabled
|
private var sponsorBlockEnabled = PlayerHelper.sponsorBlockEnabled
|
||||||
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
|
private val mainActivity get() = activity as MainActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receiver for all actions in the PiP mode
|
* Receiver for all actions in the PiP mode
|
||||||
@ -283,7 +284,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun initializeTransitionLayout() {
|
private fun initializeTransitionLayout() {
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
mainActivity.binding.container.visibility = View.VISIBLE
|
mainActivity.binding.container.visibility = View.VISIBLE
|
||||||
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
val mainMotionLayout = mainActivity.binding.mainMotionLayout
|
||||||
|
|
||||||
@ -360,16 +360,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
playerBinding.autoPlay.visibility = View.VISIBLE
|
playerBinding.autoPlay.visibility = View.VISIBLE
|
||||||
|
|
||||||
binding.playImageView.setOnClickListener {
|
binding.playImageView.setOnClickListener {
|
||||||
if (!exoPlayer.isPlaying) {
|
when {
|
||||||
// start or go on playing
|
!exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> {
|
||||||
if (exoPlayer.playbackState == Player.STATE_ENDED) {
|
|
||||||
// restart video if finished
|
|
||||||
exoPlayer.seekTo(0)
|
exoPlayer.seekTo(0)
|
||||||
}
|
}
|
||||||
exoPlayer.play()
|
!exoPlayer.isPlaying -> exoPlayer.play()
|
||||||
} else {
|
else -> exoPlayer.pause()
|
||||||
// pause the video
|
|
||||||
exoPlayer.pause()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,7 +494,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
|
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
|
||||||
playerBinding.exoTitle.visibility = View.VISIBLE
|
playerBinding.exoTitle.visibility = View.VISIBLE
|
||||||
|
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
if (!PlayerHelper.autoRotationEnabled) {
|
if (!PlayerHelper.autoRotationEnabled) {
|
||||||
// different orientations of the video are only available when auto rotation is disabled
|
// different orientations of the video are only available when auto rotation is disabled
|
||||||
val orientation = PlayerHelper.getOrientation(exoPlayer.videoSize)
|
val orientation = PlayerHelper.getOrientation(exoPlayer.videoSize)
|
||||||
@ -523,7 +518,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
if (!PlayerHelper.autoRotationEnabled) {
|
if (!PlayerHelper.autoRotationEnabled) {
|
||||||
// switch back to portrait mode if auto rotation disabled
|
// switch back to portrait mode if auto rotation disabled
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,7 +544,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
binding.playerViewsInfo.text = viewInfo
|
binding.playerViewsInfo.text = viewInfo
|
||||||
|
|
||||||
if (this::chapters.isInitialized && chapters.isNotEmpty()) {
|
if (this::chapters.isInitialized && chapters.isNotEmpty()) {
|
||||||
val chapterIndex = getCurrentChapterIndex()
|
val chapterIndex = getCurrentChapterIndex() ?: return
|
||||||
// scroll to the current chapter in the chapterRecView in the description
|
// scroll to the current chapter in the chapterRecView in the description
|
||||||
val layoutManager = binding.chaptersRecView.layoutManager as LinearLayoutManager
|
val layoutManager = binding.chaptersRecView.layoutManager as LinearLayoutManager
|
||||||
layoutManager.scrollToPositionWithOffset(chapterIndex, 0)
|
layoutManager.scrollToPositionWithOffset(chapterIndex, 0)
|
||||||
@ -1165,19 +1159,14 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
"(${chapter.start?.let { DateUtils.formatElapsedTime(it) }}) ${chapter.title}"
|
"(${chapter.start?.let { DateUtils.formatElapsedTime(it) }}) ${chapter.title}"
|
||||||
}
|
}
|
||||||
playerBinding.chapterLL.setOnClickListener {
|
playerBinding.chapterLL.setOnClickListener {
|
||||||
if (viewModel.isFullscreen.value!!) {
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
.setTitle(R.string.chapters)
|
||||||
.setTitle(R.string.chapters)
|
.setItems(titles.toTypedArray()) { _, index ->
|
||||||
.setItems(titles.toTypedArray()) { _, index ->
|
exoPlayer.seekTo(chapters[index].start!! * 1000)
|
||||||
exoPlayer.seekTo(
|
}
|
||||||
chapters[index].start!! * 1000
|
.show()
|
||||||
)
|
|
||||||
}
|
|
||||||
.show()
|
|
||||||
} else {
|
|
||||||
toggleDescription()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentChapterName()
|
setCurrentChapterName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1189,7 +1178,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
// call the function again in 100ms
|
// call the function again in 100ms
|
||||||
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
|
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
|
||||||
|
|
||||||
val chapterIndex = getCurrentChapterIndex()
|
val chapterIndex = getCurrentChapterIndex() ?: return
|
||||||
val chapterName = chapters[chapterIndex].title?.trim()
|
val chapterName = chapters[chapterIndex].title?.trim()
|
||||||
|
|
||||||
// change the chapter name textView text to the chapterName
|
// change the chapter name textView text to the chapterName
|
||||||
@ -1204,18 +1193,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
/**
|
/**
|
||||||
* Get the name of the currently played chapter
|
* Get the name of the currently played chapter
|
||||||
*/
|
*/
|
||||||
private fun getCurrentChapterIndex(): Int {
|
private fun getCurrentChapterIndex(): Int? {
|
||||||
val currentPosition = exoPlayer.currentPosition
|
val currentPosition = exoPlayer.currentPosition / 1000
|
||||||
var chapterIndex = 0
|
return chapters.indexOfFirst { currentPosition >= it.start!! }.takeIf { it >= 0 }
|
||||||
|
|
||||||
chapters.forEachIndexed { index, chapter ->
|
|
||||||
// check whether the chapter start is greater than the current player position
|
|
||||||
if (currentPosition >= chapter.start!! * 1000) {
|
|
||||||
// save chapter title if found
|
|
||||||
chapterIndex = index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return chapterIndex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMediaSource(uri: Uri, mimeType: String) {
|
private fun setMediaSource(uri: Uri, mimeType: String) {
|
||||||
@ -1356,7 +1336,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("SourceLockedOrientationActivity")
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
private fun changeOrientationMode() {
|
private fun changeOrientationMode() {
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
if (PlayerHelper.autoRotationEnabled) {
|
if (PlayerHelper.autoRotationEnabled) {
|
||||||
// enable auto rotation
|
// enable auto rotation
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||||
@ -1527,7 +1506,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
private fun killPlayerFragment() {
|
private fun killPlayerFragment() {
|
||||||
viewModel.isFullscreen.value = false
|
viewModel.isFullscreen.value = false
|
||||||
binding.playerMotionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
mainActivity.supportFragmentManager.beginTransaction()
|
mainActivity.supportFragmentManager.beginTransaction()
|
||||||
.remove(this)
|
.remove(this)
|
||||||
.commit()
|
.commit()
|
||||||
|
@ -624,7 +624,7 @@ internal class CustomExoPlayerView(
|
|||||||
playerViewModel?.isFullscreen?.value == true
|
playerViewModel?.isFullscreen?.value == true
|
||||||
binding.topBar.let {
|
binding.topBar.let {
|
||||||
it.layoutParams = (it.layoutParams as MarginLayoutParams).apply {
|
it.layoutParams = (it.layoutParams as MarginLayoutParams).apply {
|
||||||
topMargin = (if (isFullscreen) 10 else 5).dpToPx().toInt()
|
topMargin = (if (isFullscreen) 10 else 0).dpToPx().toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user