在视频仍在播放视频时,用外字幕切换视频字幕
假设我有两个视频字幕,当视频播放而不重置播放器本身时,如何切换外部字幕?例如,例如,当用户单击按钮时,
请按照
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论