diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 45f7de83f..adfcac862 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -8,6 +8,7 @@ import 'package:just_audio/just_audio.dart'; import 'package:matrix/matrix.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/utils/error_reporter.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; import '../../../utils/matrix_sdk_extensions/event_extension.dart'; @@ -174,6 +175,26 @@ class AudioPlayerState extends State { late final List waveform; + void _toggleSpeed() { + final audioPlayer = this.audioPlayer; + if (audioPlayer == null) return; + switch (audioPlayer.speed) { + case 1.0: + audioPlayer.setSpeed(1.5); + break; + case 1.5: + audioPlayer.setSpeed(2.0); + break; + case 2.0: + audioPlayer.setSpeed(0.5); + break; + case 0.5: + default: + audioPlayer.setSpeed(1.0); + break; + } + } + @override void initState() { super.initState(); @@ -183,12 +204,35 @@ class AudioPlayerState extends State { @override Widget build(BuildContext context) { final statusText = this.statusText ??= _durationString ?? '00:00'; + final audioPlayer = this.audioPlayer; return Padding( padding: const EdgeInsets.all(16), child: Row( mainAxisSize: MainAxisSize.min, children: [ - const SizedBox(width: 4), + AnimatedSize( + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + child: audioPlayer == null + ? const SizedBox.shrink() + : SizedBox( + height: 36, + width: 36, + child: IconButton( + padding: EdgeInsets.zero, + onPressed: _toggleSpeed, + //radius: AppConfig.borderRadius * 2, + icon: Text( + '${audioPlayer.speed.toString()}x', + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 12, + ), + ), + ), + ), + ), + const SizedBox(width: 8), SizedBox( width: buttonSize, height: buttonSize,