【问题标题】:flutter video player add SubtitleView颤振视频播放器添加 SubtitleView
【发布时间】: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


【解决方案1】:

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

到目前为止,我已经通过在 Flutter 上使用平台通道解决了这个问题,这也仅限于一些平台,如 android 和 ios。您还可以使用网络视频播放器和 hack Flutter 来制作视频。没有简单的答案,别再浪费时间了,通过破解你的方式而不是使用视频插件来让它工作。

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 那个插件不完整。利用每个操作系统调用原生代码的优势,使用你最原生的播放器,绕过flutter和flutter插件。
    猜你喜欢
    • 2021-09-13
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2021-10-28
    • 2021-10-12
    • 1970-01-01
    • 2019-12-10
    相关资源
    最近更新 更多