diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 4ca477fa3..c066f1847 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index c814a29cc..e3d3a7f23 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -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 = 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) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad9c4d557..28212ace1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -462,6 +462,8 @@ Continue watching No chapter Screen orientation + auto-generated + Download Service Shows a notification when downloading media.