chore: Display normal Slider when no waveform provided in audioplayer

pull/1388/merge
krille-chan 8 months ago
parent 5321a3768d
commit cd611aedc4
No known key found for this signature in database

@ -179,12 +179,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
return '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}'; return '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
} }
List<int> _getWaveform() { List<int>? _getWaveform() {
final eventWaveForm = widget.event.content final eventWaveForm = widget.event.content
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio') .tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
?.tryGetList<int>('waveform'); ?.tryGetList<int>('waveform');
if (eventWaveForm == null || eventWaveForm.isEmpty) { if (eventWaveForm == null || eventWaveForm.isEmpty) {
return List<int>.filled(AudioPlayerWidget.wavesCount, 500); return null;
} }
while (eventWaveForm.length < AudioPlayerWidget.wavesCount) { while (eventWaveForm.length < AudioPlayerWidget.wavesCount) {
for (var i = 0; i < eventWaveForm.length; i = i + 2) { for (var i = 0; i < eventWaveForm.length; i = i + 2) {
@ -200,7 +200,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
return eventWaveForm.map((i) => i > 1024 ? 1024 : i).toList(); return eventWaveForm.map((i) => i > 1024 ? 1024 : i).toList();
} }
late final List<int> waveform; late final List<int>? _waveform;
void _toggleSpeed() async { void _toggleSpeed() async {
final audioPlayer = this.audioPlayer; final audioPlayer = this.audioPlayer;
@ -229,12 +229,13 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
waveform = _getWaveform(); _waveform = _getWaveform();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
final waveform = _waveform;
final statusText = this.statusText ??= _durationString ?? '00:00'; final statusText = this.statusText ??= _durationString ?? '00:00';
final audioPlayer = this.audioPlayer; final audioPlayer = this.audioPlayer;
@ -290,6 +291,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
Expanded( Expanded(
child: Stack( child: Stack(
children: [ children: [
if (waveform != null)
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0), padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row( child: Row(
@ -325,8 +327,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
widget.event.room.client.userID widget.event.room.client.userID
? theme.colorScheme.onPrimary ? theme.colorScheme.onPrimary
: theme.colorScheme.primary, : theme.colorScheme.primary,
activeColor: Colors.transparent, activeColor: waveform == null
inactiveColor: Colors.transparent, ? widget.color
: Colors.transparent,
inactiveColor: waveform == null
? widget.color.withAlpha(128)
: Colors.transparent,
max: maxPosition, max: maxPosition,
value: currentPosition, value: currentPosition,
onChanged: (position) => audioPlayer == null onChanged: (position) => audioPlayer == null

Loading…
Cancel
Save