颤动的视频播放器添加SubtitleView

时间:2020-02-29 16:11:41

标签: flutter video exoplayer mkv srt

您好,今天的视频播放器10.8不支持.mkv容器中包含的srt文件。英语不是我的母语,我在其中使用了很多.mkv和.srt。基于Android的视频播放器的Exoplayer通过SubtitleView开箱即用地支持。

所以我决定修改视频播放器源并将exoplayer-ui添加到android / build.gradle

    dependencies {
    implementation 'com.google.android.exoplayer:exoplayer-core:2.9.6'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.9.6'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
    implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.9.6'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6'
}

然后修改video_player-0.10.8 + 1 / android / src / main / java / io / flutter / plugins / videoplayer / VideoPlayer.java并添加

import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.SubtitleView;

添加了我的全局变量...

  private PlayerView simpleExoPlayerView;
  private SubtitleView subs;
  private SimpleExoPlayer exoPlayer;

然后再创建它们...

exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
simpleExoPlayerView = new PlayerView(context);

最后将我的播放器设置为exoplayer,就像在exoplayer本机android开发中一样

surface = new Surface(textureEntry.surfaceTexture());
exoPlayer.setVideoSurface(surface);
simpleExoPlayerView.setPlayer(exoPlayer);
subs = simpleExoPlayerView.getSubtitleView();
subs.setVisibility(View.VISIBLE);

我的代码可以编译,但是我正在以BLACKSCREEN播放电影的音频,因此文件实际上正在播放。我知道我的问题取决于创建的表面,我尝试了一些无效的方法。有什么想法可以使用SubtitleView在.mkv容器中使用我的srt文件吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

我认为您可能需要为字幕添加另一个表面。

答案 1 :(得分:0)

截至今天,flutter 仍在继续,视频支持有限。 Flutter 被设计为多平台,这是主要问题,不同平台上的视频处理方式不同,视频编解码器、字幕支持、手机和平板电脑上的硬件限制(芯片组)也是 Flutters 视频插件的主要问题。

到目前为止,我已经通过在 flutter 上使用平台通道来解决这个问题,这也仅限于某些平台,例如 android 和 ios。您还可以使用网络视频播放器和 hack flutter 来制作您的视频。没有简单的答案,停止浪费时间并通过黑客攻击而不使用视频插件来让它工作。

相关问题