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"
|
"preview"
|
||||||
)
|
)
|
||||||
const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight"
|
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
|
* 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.Segment
|
||||||
import com.github.libretube.api.obj.StreamItem
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.api.obj.Streams
|
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.PictureInPictureCompat
|
||||||
import com.github.libretube.compat.PictureInPictureParamsCompat
|
import com.github.libretube.compat.PictureInPictureParamsCompat
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
@ -234,8 +235,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> Unit
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1212,7 +1212,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getSubtitleConfigs(): List<SubtitleConfiguration> = streams.subtitles.map {
|
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()
|
.setMimeType(it.mimeType).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1421,14 +1425,23 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val subtitles = streams.subtitles.map { it.name!! to it.code!! }
|
val subtitles = listOf(Subtitle(name = getString(R.string.none))).plus(streams.subtitles)
|
||||||
val subtitleOptions = listOf(getString(R.string.none) to "").plus(subtitles)
|
|
||||||
|
|
||||||
BaseBottomSheet()
|
BaseBottomSheet()
|
||||||
.setSimpleItems(subtitleOptions.map { it.first }) { index ->
|
.setSimpleItems(subtitles.map {
|
||||||
val subtitleLanguage = subtitleOptions.getOrNull(index)?.second
|
if (it.autoGenerated != true) it.name!!
|
||||||
updateCaptionsLanguage(subtitleLanguage)
|
else "${it.name} (${getString(R.string.auto_generated)})"
|
||||||
this.captionLanguage = subtitleLanguage
|
}) { 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)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
@ -462,6 +462,8 @@
|
|||||||
<string name="continue_watching">Continue watching</string>
|
<string name="continue_watching">Continue watching</string>
|
||||||
<string name="no_chapter">No chapter</string>
|
<string name="no_chapter">No chapter</string>
|
||||||
<string name="screen_orientation">Screen orientation</string>
|
<string name="screen_orientation">Screen orientation</string>
|
||||||
|
<string name="auto_generated">auto-generated</string>
|
||||||
|
|
||||||
<!-- Notification channel strings -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
<string name="download_channel_description">Shows a notification when downloading media.</string>
|
<string name="download_channel_description">Shows a notification when downloading media.</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user