mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #4510 from Bnyro/master
feat: support for selecting auto-generated captions
This commit is contained in:
commit
86a00f4702
@ -53,6 +53,7 @@ object PlayerHelper {
|
||||
"preview"
|
||||
)
|
||||
const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight"
|
||||
const val ROLE_FLAG_AUTO_GEN_SUBTITLE = C.ROLE_FLAG_SUPPLEMENTARY
|
||||
|
||||
/**
|
||||
* Create a base64 encoded DASH stream manifest
|
||||
|
@ -60,6 +60,7 @@ import com.github.libretube.api.obj.Message
|
||||
import com.github.libretube.api.obj.Segment
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.api.obj.Streams
|
||||
import com.github.libretube.api.obj.Subtitle
|
||||
import com.github.libretube.compat.PictureInPictureCompat
|
||||
import com.github.libretube.compat.PictureInPictureParamsCompat
|
||||
import com.github.libretube.constants.IntentData
|
||||
@ -234,8 +235,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -757,7 +757,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
if (binding.playerMotionLayout.progress != 1.0f) {
|
||||
// show controllers when not in picture in picture mode
|
||||
val inPipMode = PlayerHelper.pipEnabled &&
|
||||
PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
|
||||
PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
|
||||
if (!inPipMode) {
|
||||
binding.player.useController = true
|
||||
}
|
||||
@ -1005,8 +1005,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}.orEmpty()
|
||||
binding.additionalVideoInfo.text =
|
||||
"${context?.getString(R.string.category)}: ${streams.category}\n" +
|
||||
"${context?.getString(R.string.license)}: ${streams.license}\n" +
|
||||
"${context?.getString(R.string.visibility)}: $visibility"
|
||||
"${context?.getString(R.string.license)}: ${streams.license}\n" +
|
||||
"${context?.getString(R.string.visibility)}: $visibility"
|
||||
|
||||
if (streams.tags.isNotEmpty()) {
|
||||
binding.tagsRecycler.layoutManager =
|
||||
@ -1212,7 +1212,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
private fun getSubtitleConfigs(): List<SubtitleConfiguration> = streams.subtitles.map {
|
||||
SubtitleConfiguration.Builder(it.url!!.toUri()).setLanguage(it.code)
|
||||
val roleFlags =
|
||||
if (it.autoGenerated == true) PlayerHelper.ROLE_FLAG_AUTO_GEN_SUBTITLE else C.ROLE_FLAG_CAPTION
|
||||
SubtitleConfiguration.Builder(it.url!!.toUri())
|
||||
.setRoleFlags(roleFlags)
|
||||
.setLanguage(it.code)
|
||||
.setMimeType(it.mimeType).build()
|
||||
}
|
||||
|
||||
@ -1421,14 +1425,23 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
return
|
||||
}
|
||||
|
||||
val subtitles = streams.subtitles.map { it.name!! to it.code!! }
|
||||
val subtitleOptions = listOf(getString(R.string.none) to "").plus(subtitles)
|
||||
val subtitles = listOf(Subtitle(name = getString(R.string.none))).plus(streams.subtitles)
|
||||
|
||||
BaseBottomSheet()
|
||||
.setSimpleItems(subtitleOptions.map { it.first }) { index ->
|
||||
val subtitleLanguage = subtitleOptions.getOrNull(index)?.second
|
||||
updateCaptionsLanguage(subtitleLanguage)
|
||||
this.captionLanguage = subtitleLanguage
|
||||
.setSimpleItems(subtitles.map {
|
||||
if (it.autoGenerated != true) it.name!!
|
||||
else "${it.name} (${getString(R.string.auto_generated)})"
|
||||
}) { index ->
|
||||
val subtitle = subtitles.getOrNull(index) ?: return@setSimpleItems
|
||||
updateCaptionsLanguage(subtitle.code)
|
||||
trackSelector.updateParameters {
|
||||
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)
|
||||
}
|
||||
|
@ -462,6 +462,8 @@
|
||||
<string name="continue_watching">Continue watching</string>
|
||||
<string name="no_chapter">No chapter</string>
|
||||
<string name="screen_orientation">Screen orientation</string>
|
||||
<string name="auto_generated">auto-generated</string>
|
||||
|
||||
<!-- Notification channel strings -->
|
||||
<string name="download_channel_name">Download Service</string>
|
||||
<string name="download_channel_description">Shows a notification when downloading media.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user