Merge pull request #3225 from pangeachat/3218-make-clicking-non-overlay-speed-button-do-something
chore: allow user to set playback speed before audio starts playing
This commit is contained in:
commit
9a4bb6e88c
1 changed files with 26 additions and 2 deletions
|
|
@ -77,6 +77,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
// #Pangea
|
||||
StreamSubscription? _onAudioPositionChanged;
|
||||
StreamSubscription? _onAudioStateChanged;
|
||||
|
||||
double playbackSpeed = 1.0;
|
||||
// Pangea#
|
||||
|
||||
@override
|
||||
|
|
@ -175,6 +177,9 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
: matrix.audioPlayer;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
// #Pangea
|
||||
currentPlayer.setSpeed(playbackSpeed);
|
||||
// Pangea#
|
||||
if (currentPlayer.isAtEndPosition) {
|
||||
currentPlayer.seek(Duration.zero);
|
||||
} else if (currentPlayer.playing) {
|
||||
|
|
@ -250,6 +255,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
final audioPlayer = matrix.audioPlayer = AudioPlayer();
|
||||
|
||||
// #Pangea
|
||||
audioPlayer.setSpeed(playbackSpeed);
|
||||
_onAudioPositionChanged?.cancel();
|
||||
_onAudioPositionChanged =
|
||||
matrix.audioPlayer!.positionStream.listen((state) {
|
||||
|
|
@ -306,7 +312,25 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
|
||||
void _toggleSpeed() async {
|
||||
final audioPlayer = matrix.audioPlayer;
|
||||
if (audioPlayer == null) return;
|
||||
// #Pangea
|
||||
// if (audioPlayer == null) return;
|
||||
if (audioPlayer == null ||
|
||||
matrix.voiceMessageEventId.value != widget.eventId) {
|
||||
switch (playbackSpeed) {
|
||||
case 1.0:
|
||||
setState(() => playbackSpeed = 0.75);
|
||||
case 0.75:
|
||||
setState(() => playbackSpeed = 0.5);
|
||||
case 0.5:
|
||||
setState(() => playbackSpeed = 1.25);
|
||||
case 1.25:
|
||||
setState(() => playbackSpeed = 1.5);
|
||||
default:
|
||||
setState(() => playbackSpeed = 1.0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Pangea#
|
||||
switch (audioPlayer.speed) {
|
||||
// #Pangea
|
||||
// case 1.0:
|
||||
|
|
@ -599,7 +623,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
height: 20,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${audioPlayer?.speed.toString() ?? 1}x',
|
||||
'${audioPlayer?.speed.toString() ?? playbackSpeed}x',
|
||||
style: TextStyle(
|
||||
color: widget.color,
|
||||
fontSize: 9,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue