【发布时间】:2020-06-13 11:12:25
【问题描述】:
大家好,从今天开始,视频播放器 10.8 不支持 .mkv 容器中包含的 srt 文件。英语不是我的母语,我使用了很多带有 .srt 的 .mkv。 Exoplayer 是基于 android 的视频播放器,通过 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);
我的代码已编译,但我得到了正在播放的电影的音频,因此文件实际上正在播放。我知道我的问题依赖于我创建的表面,我尝试了一些不起作用的东西。有什么想法可以使用 SubtitleView 在 .mkv 容器中使用我的 srt 文件吗?
谢谢!
【问题讨论】:
-
有过这个工作吗?
-
我使用了flutter平台频道和exoplayer来让字幕工作。不要使用插件,只需调用 android 本机代码并在那里使用 exoplayer。
标签: flutter video exoplayer mkv srt