@@ -25,6 +25,7 @@ class PlayerModel extends ChangeNotifier {
2525 final PlaylistModel playlist;
2626
2727 bool showControls = false ;
28+ bool hasSubtitleTrack = false ;
2829 Timer ? controlsTimer;
2930
3031 bool _showMessageIcon = false ;
@@ -179,8 +180,15 @@ class PlayerModel extends ChangeNotifier {
179180 }();
180181
181182 initPlayerFuture? .whenComplete (() {
183+ hasSubtitleTrack = false ;
182184 _loadCaptions (item)? .then ((subs) {
183- _currentCaptions = subs;
185+ var srt = subs.toSRT ();
186+ hasSubtitleTrack = srt.isNotEmpty;
187+ player.setSubtitleTrack (
188+ SubtitleTrack .data (
189+ srt,
190+ ),
191+ );
184192 notifyListeners ();
185193 });
186194 app.send (
@@ -194,10 +202,7 @@ class PlayerModel extends ChangeNotifier {
194202 notifyListeners ();
195203 }
196204
197- LocalClosedCaptionFile ? _currentCaptions;
198-
199205 String fullscreenTooltipText = 'Double-tap or long-tap to toggle fullscreen' ;
200- LocalClosedCaptionFile ? get currentCaptions => _currentCaptions;
201206
202207 Future <double > getVideoDuration (String url) async {
203208 // mediakit will parse segment durations for a minute while loading them,
@@ -454,8 +459,7 @@ class PlayerModel extends ChangeNotifier {
454459
455460 Future <LocalClosedCaptionFile >? _loadCaptions (VideoList item) {
456461 if (item.url.contains ('youtu' )) {
457- item.subs = item.url;
458- return compute (_loadYoutubeCaptionsFuture, item);
462+ return compute (_loadYoutubeCaptionsFuture, item.url);
459463 }
460464 var subsUrl = item.subs ?? '' ;
461465 if (subsUrl.isEmpty) return null ;
@@ -470,10 +474,9 @@ class PlayerModel extends ChangeNotifier {
470474 }
471475
472476 static Future <LocalClosedCaptionFile > _loadYoutubeCaptionsFuture (
473- VideoList item ,
477+ String url ,
474478 ) async {
475- final subs = await getYoutubeSubtitles (item.url);
476- if (subs.captions.isEmpty) item.subs = '' ;
479+ final subs = await getYoutubeSubtitles (url);
477480 return subs;
478481 }
479482
@@ -609,6 +612,7 @@ class PlayerModel extends ChangeNotifier {
609612 }
610613
611614 bool hasCaptions () {
615+ if (hasSubtitleTrack) return true ;
612616 final item = playlist.getItem (playlist.pos);
613617 final subs = item? .subs;
614618 return subs != null && subs.isNotEmpty;
0 commit comments