50 lines
1.6 KiB
Dart
50 lines
1.6 KiB
Dart
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
|
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/services/media/media.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class AudioSlider extends StatelessWidget {
|
|
final String tag;
|
|
final bool showTimer;
|
|
const AudioSlider({Key? key, required this.tag, this.showTimer = false})
|
|
: super(key: key);
|
|
|
|
bool get _isPlaying => MediaService.audioPlayerTag == tag;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return IgnorePointer(
|
|
ignoring: MediaService.audioPlayerTag != tag,
|
|
child: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: StreamBuilder<Duration>(
|
|
stream: _isPlaying ? MediaService.audioPlayer.positionStream : null,
|
|
builder: (context, snapshot) {
|
|
return ProgressBar(
|
|
total: MediaService.audioPlayer.duration ?? Duration.zero,
|
|
progress: snapshot.data ?? Duration.zero,
|
|
buffered:
|
|
_isPlaying ? MediaService.audioPlayer.bufferedPosition : null,
|
|
thumbRadius: 6,
|
|
barHeight: 3,
|
|
timeLabelTextStyle: TextStyle(
|
|
fontSize: showTimer ? null : 0,
|
|
height: showTimer ? null : 0,
|
|
fontFamily: DesignConfig.fontFamily.replaceAll(
|
|
'-FA',
|
|
'',
|
|
),
|
|
),
|
|
onSeek: (value) => _onSeek(value.inMilliseconds),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onSeek(int value) {
|
|
MediaService.audioPlayer.seek(Duration(milliseconds: value));
|
|
}
|
|
}
|