|
1 | 1 | # Subtitle Player |
2 | | -A Flutter package for synchronizing subtitles with video and audio playback. |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://pub.dev/packages/subtitle_player/score"><img src="https://img.shields.io/pub/likes/subtitle_player" alt="likes"></a> |
| 5 | + <a href="https://pub.dev/packages/subtitle_player/score"><img src="https://img.shields.io/pub/points/subtitle_player" alt="pub points"></a> |
| 6 | + <a href="https://codecov.io/gh/crazelu/subtitle_player"><img src="https://codecov.io/gh/crazelu/subtitle_player/graph/badge.svg" alt="code coverage"/></a> |
| 7 | +</p> |
| 8 | + |
| 9 | + |
| 10 | +A library for synchronizing subtitles with video and audio playback. |
| 11 | + |
3 | 12 |
|
4 | 13 | ## Features 📦 |
5 | 14 |
|
6 | | -- [x] Load SubRip, WebVTT and LRC subtitles |
| 15 | +- [x] Load SubRip, WebVTT and LRC formats |
7 | 16 | - [x] Play, pause and seek support |
8 | 17 | - [x] Adjust playback speed |
9 | 18 |
|
10 | 19 | ## Install 🚀 |
11 | 20 |
|
12 | | -In the `pubspec.yaml` of your flutter project, add the `subtitle_player` dependency: |
| 21 | +In the `pubspec.yaml` of your Flutter/Dart project, add the `subtitle_player` dependency: |
13 | 22 |
|
14 | 23 | ```yaml |
15 | 24 | dependencies: |
16 | | - subtitle_player: |
17 | | - git: |
18 | | - url: https://github.com/Crazelu/subtitle_player.git |
| 25 | + subtitle_player: ^1.0.0 |
19 | 26 | ``` |
20 | 27 |
|
21 | 28 | ## Import the package in your project 📥 |
@@ -77,6 +84,21 @@ Subscribe to `SubtitleController` for changes using `ValuelistenableBuilder`, `L |
77 | 84 | ) |
78 | 85 | ``` |
79 | 86 |
|
| 87 | +Alternatively, you can attach a listener to the audio/video playback's position and call the `sync` method whenever the position changes. |
| 88 | + |
| 89 | +```dart |
| 90 | +// Example with JustAudio |
| 91 | +
|
| 92 | +final player = AudioPlayer(); |
| 93 | +final positionStream = player.createPositionStream(); |
| 94 | +
|
| 95 | +final streamSubscription = positionStream.listen((position) { |
| 96 | + subtitleController.sync(position); |
| 97 | +}); |
| 98 | +
|
| 99 | +// make sure to cancel the stream subscription when ready to release resources |
| 100 | +``` |
| 101 | + |
80 | 102 | Check the [example project](https://github.com/Crazelu/subtitle_player/tree/main/example) for more detailed usage examples both for video and audio playing. |
81 | 103 |
|
82 | 104 | ## Demo 📷 |
|
0 commit comments