在视频仍在播放视频时,用外字幕切换视频字幕

发布于 2025-02-10 22:14:05 字数 994 浏览 0 评论 0原文

假设我有两个视频字幕,当视频播放而不重置播放器本身时,如何切换外部字幕?例如,例如,当用户单击按钮时,

请按照

binding.button.setOnClickListener {
    val k = player.currentPosition // Get the latest player's current position
    subtitle = SubtitleConfiguration.Builder(newSubtitleUri)
        .setMimeType(MimeTypes.APPLICATION_SUBRIP)
        .setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
        .build()
    mediaItem = MediaItem.Builder()
        .setUri(videoUri)
        .setSubtitleConfigurations(ImmutableList.of(subtitle))
        .build()
    player.setMediaItem(mediaItem)
    player.prepare()
    player.seekTo(k) // seek to the latest position, if we don't do this it would just play back to the beginning of the video
}

这是一个缺点,因为玩家一旦将黑屏拆分一秒钟,然后返回最新的播放器位置。我想更改字幕而不代表视频,因此字幕切换可以是无缝的,并且不会导致我指的是我所指的分裂黑屏。

此github问题post 告诉我,当前的Exoplayer不支持此问题。但是,嘿,如果YouTube可以做到,为什么不能?

Let's say I have two subtitles for a video, how do you switch an exoplayer's subtitles while the video is playing without resetting the player itself? Like for an example when a user click a button

By following the exoplayer documentation, my current implementation is like this:

binding.button.setOnClickListener {
    val k = player.currentPosition // Get the latest player's current position
    subtitle = SubtitleConfiguration.Builder(newSubtitleUri)
        .setMimeType(MimeTypes.APPLICATION_SUBRIP)
        .setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
        .build()
    mediaItem = MediaItem.Builder()
        .setUri(videoUri)
        .setSubtitleConfigurations(ImmutableList.of(subtitle))
        .build()
    player.setMediaItem(mediaItem)
    player.prepare()
    player.seekTo(k) // seek to the latest position, if we don't do this it would just play back to the beginning of the video
}

This has a downside, for once the player would show a black screen for a split second and return to the latest player position. I want to change the subtitle without repreparing the video, so the subtitle switching can be seamless and it wouldn't lead to the split-second black screen I was referring about.

This GitHub issue post tells me that exoplayer doesn't support this currently. But hey, if YouTube could do it, why couldn't I?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文