subtitle 0.1.0-beta.3 copy "subtitle: ^0.1.0-beta.3" to clipboard
subtitle: ^0.1.0-beta.3 copied to clipboard

outdated

A library that makes it easy to work with multiple subtitle/caption file formats, written with highly efficient code, highly customizable (90%), supports Null Safety.

example/subtitle_example.dart

import 'package:subtitle/subtitle.dart';

/// TTML and DFXP parsing
const ttmlText = '''
<?xml version="1.0" encoding="UTF-8"?>
<tt xmlns="http://www.w3.org/ns/ttml">
  <head>
    <metadata xmlns:ttm="http://www.w3.org/ns/ttml#metadata">
      <ttm:title>Timed Text TTML Example</ttm:title>
      <ttm:copyright>The Authors (c) 2006</ttm:copyright>
    </metadata>
    <styling xmlns:tts="http://www.w3.org/ns/ttml#styling">
      <!-- s1 specifies default color, font, and text alignment -->
      <style xml:id="s1"
        tts:color="white"
        tts:fontFamily="proportionalSansSerif"
        tts:fontSize="22px"
        tts:textAlign="center"
      />
      <!-- alternative using yellow text but otherwise the same as style s1 -->
      <style xml:id="s2" style="s1" tts:color="yellow"/>
      <!-- a style based on s1 but justified to the right -->
      <style xml:id="s1Right" style="s1" tts:textAlign="end" />     
      <!-- a style based on s2 but justified to the left -->
      <style xml:id="s2Left" style="s2" tts:textAlign="start" />
    </styling>
    <layout xmlns:tts="http://www.w3.org/ns/ttml#styling">
      <region xml:id="subtitleArea"
        style="s1"
        tts:extent="560px 62px"
        tts:padding="5px 3px"
        tts:backgroundColor="black"
        tts:displayAlign="after"
      />
    </layout> 
  </head>
  <body region="subtitleArea">
    <div>
      <p xml:id="subtitle1" begin="0.76s" end="3.45s">
        It seems a paradox, does it not,
      </p>
      <p xml:id="subtitle2" begin="5.0s" end="10.0s">
        that the image formed on<br/>
        the Retina should be inverted?
      </p>
      <p xml:id="subtitle3" begin="10.0s" end="16.0s" style="s2">
        It is puzzling, why is it<br/>
        we do not see things upside-down?
      </p>
      <p xml:id="subtitle4" begin="17.2s" end="23.0s">
        You have never heard the Theory,<br/>then, that the Brain also is inverted?
      </p>
      <p xml:id="subtitle5" begin="23.0s" end="27.0s" style="s2">
        No indeed! What a beautiful fact!
      </p>
    </div>
  </body>
</tt>
''';

Future<void> main() async {
  var sp = SubtitleProvider.fromString(
    data: ttmlText,
    type: SubtitleType.ttml,
  );
  var sc = SubtitleController(provider: sp);
  await sc.initial();
  var s = sc.durationSearch(Duration(seconds: 29));
  print(s?.data ?? 'No subtitle in range of provided duration.');
}

void printResult(List<Subtitle> subtitles) {
  subtitles.sort((s1, s2) => s1.compareTo(s2));
  for (var result in subtitles) {
    print(
        '(${result.index}) Start: ${result.start}, end: ${result.end} [${result.data}]');
  }
}
30
likes
0
pub points
87%
popularity

Publisher

verified publishermuhmdhsn313.me

A library that makes it easy to work with multiple subtitle/caption file formats, written with highly efficient code, highly customizable (90%), supports Null Safety.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

universal_io

More

Packages that depend on subtitle