本文介绍了支持srt/vtt字幕并在视频播放器抖动中同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中播放srt字幕.到目前为止,我已经集成了 srt_parser .另外,我可以通过此代码获取玩家的当前位置

I want to play srt subtitles in my app. I have integrated srt_parser so far.Also, I am able to get the current position of the player by this code

  inMilliseconds = _videoPlayerController.value.position.inMilliseconds;

这是srt解析代码.

  String data = '''1
  00:00:01,600 --> 00:00:04,200
  English (US)

  2
  00:00:05,900 --> 00:00:07,999
  This is a subtitle in American English

  3
  00:00:10,000 --> 00:00:14,000
  Adding subtitles is very easy to do''';

  srtParser() {
  List<Subtitle> subtitles = parseSrt(data);
  for (Subtitle item in subtitles) {
  print(
      'inMilliseconds ${inMilliseconds}  Begin is: ${item.range.begin} and End is:
  ${item.range.end}');
  if (inMilliseconds > item.range.begin &&
      inMilliseconds < item.range.end) {
    for (var line in item.parsedLines) {
      for (var subLine in line.subLines) {
        print(
            'myline${item.parsedLines.indexOf(line)} subline${line.subLines.indexOf(subLine)} is: ${subLine.rawString}');
        setState(() {
          videoSubtitle =
              '${item.parsedLines.indexOf(line)} ${line.subLines.indexOf(subLine)} ${subLine.rawString}';
        });
      }
    }
  } else {
    setState(() {
      videoSubtitle = null;
    });
  }
}
if (subtitles[0].parsedLines[0].subLines[1].htmlCode.b == true) {
  print('true');
}

}

那么我该如何将字幕与视频播放器位置同步?

So How can i sync subtitle with Video player position?

现在我正在解析srt字符串.如何从srt文件中解析?

And right now I am parsing srt string. How can I parse it from srt file?

推荐答案

目前,我正在使用 subtitle_wrapper_package

在视频播放器中支持vtt字幕.

which supports vtt subtitle in the video player.

SubTitleWrapper(
  videoPlayerController: chewieController.videoPlayerController,
  subtitleController: SubtitleController(
    subtitleUrl: subtitleUrl,
    showSubtitles: true,
  ),
  subtitleStyle:
      SubtitleStyle(textColor: Colors.white, hasBorder: true),
  videoChild: Chewie(
    controller: chewieController,
  )),

输出:

这篇关于支持srt/vtt字幕并在视频播放器抖动中同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 22:25