Skip to content

Commit 94f73df

Browse files
Added audio speed functionality
1 parent d31437c commit 94f73df

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/providers/podcast_provider.dart

+12
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class PodcastProvider with ChangeNotifier {
6363

6464
late String? currentPodcastTimeRemaining;
6565

66+
String audioSpeedButtonLabel = '1.0x';
67+
68+
List<String> audioSpeedOptions = ['0.5x', '1.0x', '1.5x', '2.0x'];
69+
6670
Future<void> initial(
6771
BuildContext context,
6872
) async {
@@ -220,6 +224,14 @@ class PodcastProvider with ChangeNotifier {
220224
}
221225
}
222226

227+
void audioSpeedButtonClicked() {
228+
int index = audioSpeedOptions.indexOf(audioSpeedButtonLabel);
229+
int newIndex = (index + 1) % audioSpeedOptions.length;
230+
audioSpeedButtonLabel = audioSpeedOptions[newIndex];
231+
player.setPlaybackRate(double.parse(audioSpeedButtonLabel.substring(0, 3)));
232+
notifyListeners();
233+
}
234+
223235
void updatePlaybackBar() {
224236
// player.getDuration().then((Duration? value) {
225237
// podcastDuration = value;

lib/views/player/main_player.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ class MainPlayer extends ConsumerWidget {
178178
child: Row(
179179
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
180180
children: [
181+
// Playback speed
181182
TextButton(
182-
onPressed: () {},
183-
child: const Text(
184-
'1.0x',
185-
style: TextStyle(
183+
onPressed: () => ref
184+
.read(podcastProvider.notifier)
185+
.audioSpeedButtonClicked(),
186+
child: Text(
187+
ref.watch(podcastProvider).audioSpeedButtonLabel,
188+
style: const TextStyle(
186189
fontWeight: FontWeight.bold,
187190
),
188191
),

0 commit comments

Comments
 (0)