@@ -5837,88 +5837,90 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen>
58375837 final canDownloadRemote =
58385838 ! audio && item is AggregatedItem && _canDownloadRemoteSubtitles (item);
58395839
5840- final int ? currentStreamIndex;
5841- if (audio) {
5842- currentStreamIndex =
5843- _manager.audioStreamIndex ??
5844- streams.where ((s) => s['IsDefault' ] == true ).firstOrNull? ['Index' ]
5845- as int ? ;
5846- } else {
5847- final subIdx = _manager.subtitleStreamIndex;
5848- currentStreamIndex =
5849- subIdx ??
5850- streams.where ((s) => s['IsDefault' ] == true ).firstOrNull? ['Index' ]
5851- as int ? ;
5852- }
5853- final isSubsOff = ! audio && _manager.subtitleStreamIndex == - 1 ;
5854-
5855- final options = < TrackOption > [
5856- if (! audio) TrackOption (label: l10n.off),
5857- ...optionStreams.asMap ().entries.map ((entry) {
5858- final index = entry.key;
5859- final trackNumber = index + 1 ;
5860- final s = entry.value;
5861- final displayTitle = s['DisplayTitle' ] as String ? ;
5862- final title = s['Title' ] as String ? ;
5863- final language = s['Language' ] as String ? ;
5864- final codec = s['Codec' ] as String ? ;
5865- final label =
5866- displayTitle ??
5867- title ??
5868- language ??
5869- l10n.streamTypeFallback (streamType, index + 1 );
5870- final subtitle = audio
5871- ? [
5872- if (language != null && displayTitle != null ) language,
5873- if (codec != null ) codec.toUpperCase (),
5874- if (s['Channels' ] != null ) '${s ['Channels' ]}ch' ,
5875- ].join (' · ' )
5876- : (() {
5877- final subtitleType =
5878- ((codec == null || codec.isEmpty) ? 'Unknown' : codec)
5879- .toUpperCase ();
5880- final deliveryMethod = (s['DeliveryMethod' ] as String ? )
5881- ? .trim ()
5882- .toLowerCase ();
5883- final location = s['IsExternal' ] == true
5884- ? 'External'
5885- : (deliveryMethod == 'embed' ? 'Embedded' : 'Internal' );
5886- return '$subtitleType · $location ' ;
5887- })();
5888- return TrackOption (
5889- label: '$trackNumber - $label ' ,
5890- subtitle: subtitle.isNotEmpty ? subtitle : null ,
5891- scrollLabel: true ,
5892- scrollSubtitle: true ,
5893- );
5894- }),
5895- if (canDownloadRemote)
5896- TrackOption (
5897- label: l10n.downloadSubtitlesLabel,
5898- subtitle: l10n.searchOpenSubtitlesPlugin,
5899- ),
5900- ];
5840+ unawaited (() async {
5841+ final int ? currentStreamIndex;
5842+ if (audio) {
5843+ currentStreamIndex =
5844+ _manager.audioStreamIndex ??
5845+ streams.where ((s) => s['IsDefault' ] == true ).firstOrNull? ['Index' ]
5846+ as int ? ;
5847+ } else {
5848+ final subIdx = await _manager.getSubtitleStreamIndexAsync ();
5849+ currentStreamIndex =
5850+ subIdx ??
5851+ streams.where ((s) => s['IsDefault' ] == true ).firstOrNull? ['Index' ]
5852+ as int ? ;
5853+ }
5854+ final isSubsOff = ! audio && currentStreamIndex == - 1 ;
5855+
5856+ final options = < TrackOption > [
5857+ if (! audio) TrackOption (label: l10n.off),
5858+ ...optionStreams.asMap ().entries.map ((entry) {
5859+ final index = entry.key;
5860+ final trackNumber = index + 1 ;
5861+ final s = entry.value;
5862+ final displayTitle = s['DisplayTitle' ] as String ? ;
5863+ final title = s['Title' ] as String ? ;
5864+ final language = s['Language' ] as String ? ;
5865+ final codec = s['Codec' ] as String ? ;
5866+ final label =
5867+ displayTitle ??
5868+ title ??
5869+ language ??
5870+ l10n.streamTypeFallback (streamType, index + 1 );
5871+ final subtitle = audio
5872+ ? [
5873+ if (language != null && displayTitle != null ) language,
5874+ if (codec != null ) codec.toUpperCase (),
5875+ if (s['Channels' ] != null ) '${s ['Channels' ]}ch' ,
5876+ ].join (' · ' )
5877+ : (() {
5878+ final subtitleType =
5879+ ((codec == null || codec.isEmpty) ? 'Unknown' : codec)
5880+ .toUpperCase ();
5881+ final deliveryMethod = (s['DeliveryMethod' ] as String ? )
5882+ ? .trim ()
5883+ .toLowerCase ();
5884+ final location = s['IsExternal' ] == true
5885+ ? 'External'
5886+ : (deliveryMethod == 'embed' ? 'Embedded' : 'Internal' );
5887+ return '$subtitleType · $location ' ;
5888+ })();
5889+ return TrackOption (
5890+ label: '$trackNumber - $label ' ,
5891+ subtitle: subtitle.isNotEmpty ? subtitle : null ,
5892+ scrollLabel: true ,
5893+ scrollSubtitle: true ,
5894+ );
5895+ }),
5896+ if (canDownloadRemote)
5897+ TrackOption (
5898+ label: l10n.downloadSubtitlesLabel,
5899+ subtitle: l10n.searchOpenSubtitlesPlugin,
5900+ ),
5901+ ];
59015902
5902- final int ? selectedIndex;
5903- if (audio) {
5904- final idx = currentStreamIndex != null
5905- ? streams.indexWhere ((s) => s['Index' ] == currentStreamIndex)
5906- : - 1 ;
5907- selectedIndex = idx >= 0 ? idx : null ;
5908- } else {
5909- if (isSubsOff || (currentStreamIndex == null && streams.isNotEmpty)) {
5910- selectedIndex = 0 ;
5911- } else if (currentStreamIndex != null ) {
5912- final idx = optionStreams.indexWhere (
5913- (s) => s['Index' ] == currentStreamIndex,
5914- );
5915- selectedIndex = idx >= 0 ? idx + 1 : null ;
5903+ final int ? selectedIndex;
5904+ if (audio) {
5905+ final idx = currentStreamIndex != null
5906+ ? streams.indexWhere ((s) => s['Index' ] == currentStreamIndex)
5907+ : - 1 ;
5908+ selectedIndex = idx >= 0 ? idx : null ;
59165909 } else {
5917- selectedIndex = null ;
5910+ if (isSubsOff || (currentStreamIndex == null && streams.isNotEmpty)) {
5911+ selectedIndex = 0 ;
5912+ } else if (currentStreamIndex != null ) {
5913+ final idx = optionStreams.indexWhere (
5914+ (s) => s['Index' ] == currentStreamIndex,
5915+ );
5916+ selectedIndex = idx >= 0 ? idx + 1 : null ;
5917+ } else {
5918+ selectedIndex = null ;
5919+ }
59185920 }
5919- }
59205921
5921- unawaited (() async {
5922+ if (! mounted) return ;
5923+
59225924 final result = await TrackSelectorDialog .show (
59235925 context,
59245926 title: audio ? l10n.audioTrack : l10n.subtitleTrack,
0 commit comments