feat: Add speed button for audioplayer
This commit is contained in:
parent
278c3d165b
commit
bf1f8ebaf5
1 changed files with 45 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import 'package:just_audio/just_audio.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:path_provider/path_provider.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/error_reporter.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import '../../../utils/matrix_sdk_extensions/event_extension.dart';
|
import '../../../utils/matrix_sdk_extensions/event_extension.dart';
|
||||||
|
|
@ -174,6 +175,26 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
|
|
||||||
late final List<int> waveform;
|
late final List<int> 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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -183,12 +204,35 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final statusText = this.statusText ??= _durationString ?? '00:00';
|
final statusText = this.statusText ??= _durationString ?? '00:00';
|
||||||
|
final audioPlayer = this.audioPlayer;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
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(
|
SizedBox(
|
||||||
width: buttonSize,
|
width: buttonSize,
|
||||||
height: buttonSize,
|
height: buttonSize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue