mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
fix: captions can't be disabled
This commit is contained in:
parent
f84d9b4a17
commit
67b46951d4
@ -168,7 +168,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
*/
|
*/
|
||||||
private lateinit var exoPlayer: ExoPlayer
|
private lateinit var exoPlayer: ExoPlayer
|
||||||
private lateinit var trackSelector: DefaultTrackSelector
|
private lateinit var trackSelector: DefaultTrackSelector
|
||||||
private var captionLanguage = PlayerHelper.defaultSubtitleCode
|
private var currentSubtitle = Subtitle(code = PlayerHelper.defaultSubtitleCode)
|
||||||
|
|
||||||
private val cronetDataSourceFactory = CronetDataSource.Factory(
|
private val cronetDataSourceFactory = CronetDataSource.Factory(
|
||||||
CronetHelper.cronetEngine,
|
CronetHelper.cronetEngine,
|
||||||
@ -334,7 +334,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
if (currentId == transitionEndId) {
|
if (currentId == transitionEndId) {
|
||||||
viewModel.isMiniPlayerVisible.value = true
|
viewModel.isMiniPlayerVisible.value = true
|
||||||
// disable captions temporarily
|
// disable captions temporarily
|
||||||
updateCaptionsLanguage(null)
|
updateCurrentSubtitle(null)
|
||||||
binding.player.useController = false
|
binding.player.useController = false
|
||||||
commentsViewModel.setCommentSheetExpand(null)
|
commentsViewModel.setCommentSheetExpand(null)
|
||||||
binding.sbSkipBtn.isGone = true
|
binding.sbSkipBtn.isGone = true
|
||||||
@ -343,7 +343,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
} else if (currentId == transitionStartId) {
|
} else if (currentId == transitionStartId) {
|
||||||
viewModel.isMiniPlayerVisible.value = false
|
viewModel.isMiniPlayerVisible.value = false
|
||||||
// re-enable captions
|
// re-enable captions
|
||||||
updateCaptionsLanguage(captionLanguage)
|
updateCurrentSubtitle(currentSubtitle)
|
||||||
binding.player.useController = true
|
binding.player.useController = true
|
||||||
commentsViewModel.setCommentSheetExpand(true)
|
commentsViewModel.setCommentSheetExpand(true)
|
||||||
mainMotionLayout.progress = 0F
|
mainMotionLayout.progress = 0F
|
||||||
@ -1212,8 +1212,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getSubtitleConfigs(): List<SubtitleConfiguration> = streams.subtitles.map {
|
private fun getSubtitleConfigs(): List<SubtitleConfiguration> = streams.subtitles.map {
|
||||||
val roleFlags =
|
val roleFlags = getSubtitleRoleFlags(it)
|
||||||
if (it.autoGenerated == true) PlayerHelper.ROLE_FLAG_AUTO_GEN_SUBTITLE else C.ROLE_FLAG_CAPTION
|
|
||||||
SubtitleConfiguration.Builder(it.url!!.toUri())
|
SubtitleConfiguration.Builder(it.url!!.toUri())
|
||||||
.setRoleFlags(roleFlags)
|
.setRoleFlags(roleFlags)
|
||||||
.setLanguage(it.code)
|
.setLanguage(it.code)
|
||||||
@ -1257,7 +1256,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the default subtitle if available
|
// set the default subtitle if available
|
||||||
updateCaptionsLanguage(captionLanguage)
|
updateCurrentSubtitle(currentSubtitle)
|
||||||
|
|
||||||
// set media source and resolution in the beginning
|
// set media source and resolution in the beginning
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
@ -1438,22 +1437,20 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
) { index ->
|
) { index ->
|
||||||
val subtitle = subtitles.getOrNull(index) ?: return@setSimpleItems
|
val subtitle = subtitles.getOrNull(index) ?: return@setSimpleItems
|
||||||
updateCaptionsLanguage(subtitle.code)
|
updateCurrentSubtitle(subtitle)
|
||||||
trackSelector.updateParameters {
|
this.currentSubtitle = subtitle
|
||||||
trackSelector.updateParameters {
|
|
||||||
val roleFlags = if (subtitle.autoGenerated != true) {
|
|
||||||
C.ROLE_FLAG_CAPTION
|
|
||||||
} else {
|
|
||||||
PlayerHelper.ROLE_FLAG_AUTO_GEN_SUBTITLE
|
|
||||||
}
|
|
||||||
this.setPreferredTextRoleFlags(roleFlags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.captionLanguage = subtitle.code
|
|
||||||
}
|
}
|
||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSubtitleRoleFlags(subtitle: Subtitle?): Int {
|
||||||
|
return if (subtitle?.autoGenerated != true) {
|
||||||
|
C.ROLE_FLAG_CAPTION
|
||||||
|
} else {
|
||||||
|
PlayerHelper.ROLE_FLAG_AUTO_GEN_SUBTITLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onQualityClicked() {
|
override fun onQualityClicked() {
|
||||||
// get the available resolutions
|
// get the available resolutions
|
||||||
val resolutions = getAvailableResolutions()
|
val resolutions = getAvailableResolutions()
|
||||||
@ -1538,7 +1535,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
binding.linLayout.isGone = true
|
binding.linLayout.isGone = true
|
||||||
|
|
||||||
updateCaptionsLanguage(null)
|
updateCurrentSubtitle(null)
|
||||||
} else {
|
} else {
|
||||||
// close button got clicked in PiP mode
|
// close button got clicked in PiP mode
|
||||||
// pause the video and keep the app alive
|
// pause the video and keep the app alive
|
||||||
@ -1556,7 +1553,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
binding.linLayout.isVisible = true
|
binding.linLayout.isVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCaptionsLanguage(captionLanguage)
|
updateCurrentSubtitle(currentSubtitle)
|
||||||
|
|
||||||
binding.optionsLL.post {
|
binding.optionsLL.post {
|
||||||
binding.optionsLL.requestLayout()
|
binding.optionsLL.requestLayout()
|
||||||
@ -1564,11 +1561,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateCaptionsLanguage(language: String?) {
|
private fun updateCurrentSubtitle(subtitle: Subtitle?) = trackSelector.updateParameters {
|
||||||
trackSelector.updateParameters {
|
val roleFlags = if (subtitle?.code != null) getSubtitleRoleFlags(subtitle) else 0
|
||||||
setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION)
|
setPreferredTextRoleFlags(roleFlags)
|
||||||
setPreferredTextLanguage(language)
|
setPreferredTextLanguage(subtitle?.code)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onUserLeaveHint() {
|
fun onUserLeaveHint() {
|
||||||
|
Loading…
Reference in New Issue
Block a user