11import 'dart:async' ;
2+ import 'dart:convert' ;
23import 'dart:io' ;
34import 'dart:math' ;
45
@@ -19,6 +20,7 @@ typedef OnPlayProgressChange = Function(int currentPostion, int duration);
1920typedef PlayNextCallback = Function ();
2021typedef PlayPreviousCallback = Function ();
2122typedef OnRateMenuTap = Function (Rate );
23+ typedef AudioTrackCheckedCallback = Function (int );
2224
2325/// Default Panel Widget
2426class AlistPlayerSkin extends StatefulWidget {
@@ -437,20 +439,31 @@ class AlistPlayerSkinState extends State<AlistPlayerSkin> {
437439
438440 if (_audioTracks != null && _audioTracks! .length > 1 )
439441 IconButton (
440- icon: const Text (
441- "音轨" ,
442- style: TextStyle (color: Colors .white),
442+ icon: Text (
443+ Intl .playerSkin_audioTrack.tr ,
444+ style: const TextStyle (color: Colors .white),
443445 ),
444446 onPressed: () {
445447 if (_locked) {
446448 return ;
447449 }
448450 _hideTimer? .cancel ();
449- var nextAudioTrackIndex =
450- (_audioTrackIndex + 1 ) % _audioTracks! .length;
451- _player.selectTrack (
452- _audioTracks! [nextAudioTrackIndex].trackIndex ?? 0 );
453- _audioTrackIndex = nextAudioTrackIndex;
451+
452+ var dialogTag = "AudioTracSelectorDialog" ;
453+ SmartDialog .show (
454+ builder: (context) {
455+ return AudioTracSelectorDialog (
456+ audioTracks: _audioTracks! ,
457+ index: _audioTrackIndex,
458+ callback: (audioTrackIndex) {
459+ _audioTrackIndex = audioTrackIndex;
460+ _player.selectTrack (
461+ _audioTracks! [audioTrackIndex].trackIndex ?? 0 );
462+ SmartDialog .dismiss (tag: dialogTag);
463+ },
464+ );
465+ },
466+ tag: dialogTag);
454467 },
455468 ),
456469
@@ -1290,3 +1303,57 @@ class HorizontalRateMenuDialog extends StatelessWidget {
12901303 );
12911304 }
12921305}
1306+
1307+ class AudioTracSelectorDialog extends StatelessWidget {
1308+ const AudioTracSelectorDialog ({
1309+ super .key,
1310+ required this .audioTracks,
1311+ required this .index,
1312+ required this .callback,
1313+ });
1314+
1315+ final List <AVPTrackInfo > audioTracks;
1316+ final int index;
1317+ final AudioTrackCheckedCallback callback;
1318+
1319+ @override
1320+ Widget build (BuildContext context) {
1321+ List <Widget > widgets = [];
1322+ for (var i = 0 ; i < audioTracks.length; i++ ) {
1323+ Widget widget = GestureDetector (
1324+ onTap: () {
1325+ if (index != i) {
1326+ callback (i);
1327+ }
1328+ },
1329+ child: Padding (
1330+ padding: const EdgeInsets .only (left: 5 , right: 20 ),
1331+ child: Row (
1332+ mainAxisSize: MainAxisSize .min,
1333+ children: [
1334+ Checkbox (
1335+ value: index == i,
1336+ onChanged: (checked) {
1337+ if (checked == true ) {
1338+ callback (i);
1339+ }
1340+ }),
1341+ Text ("${Intl .playerSkin_audioTrack .tr }:${i + 1 }" )
1342+ ],
1343+ ),
1344+ ),
1345+ );
1346+ widgets.add (widget);
1347+ }
1348+ return Container (
1349+ decoration: BoxDecoration (
1350+ color: context.theme.colorScheme.background,
1351+ borderRadius: const BorderRadius .all (Radius .circular (10 ))),
1352+ padding: const EdgeInsets .symmetric (vertical: 10 ),
1353+ child: Column (
1354+ mainAxisSize: MainAxisSize .min,
1355+ children: widgets,
1356+ ),
1357+ );
1358+ }
1359+ }
0 commit comments