From 6ed9c239011dc34c18adef68824775c5208e64b4 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Sun, 26 Feb 2023 00:32:58 +0100 Subject: [PATCH] music is working on a android phone --- lib/pages/interval_page.dart | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 8239d09..619d969 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -11,14 +11,15 @@ class IntervalTimerPage extends StatefulWidget { } class _IntervalTimerPageState extends State { - final Duration _warmupDuration = const Duration(minutes: 5); - final Duration _cooldownDuration = const Duration(minutes: 5); - final Duration _highIntensityDuration = const Duration(minutes: 4); - final Duration _lowIntensityDuration = const Duration(minutes: 3); + final Duration _warmupDuration = const Duration(seconds: 5); + final Duration _cooldownDuration = const Duration(seconds: 5); + final Duration _highIntensityDuration = const Duration(seconds: 4); + final Duration _lowIntensityDuration = const Duration(seconds: 3); late Duration _totalDuration = const Duration(minutes: 35); AudioPlayer warmUpPlayer = AudioPlayer(); AudioPlayer workoutPlayer = AudioPlayer(); AudioPlayer coolDownPlayer = AudioPlayer(); + final AudioCache _audioCache = AudioCache(); final int _numHighIntensityBlocks = 4; final int _numLowIntensityBlocks = 3; @@ -49,7 +50,8 @@ class _IntervalTimerPageState extends State { }, ); _isPaused = false; - await AudioPlayer().play(UrlSource('assets/go.mp3')); + Source source = AssetSource('go.mp3'); + await AudioPlayer().play(source); _timer = Timer.periodic(const Duration(seconds: 1), (_) => _tick()); Future.delayed(const Duration(seconds: 1)).then((value) { @@ -80,20 +82,23 @@ class _IntervalTimerPageState extends State { } Future _playWarmUpMusic() async { + Source source = AssetSource('warmUp.mp3'); await warmUpPlayer.setReleaseMode(ReleaseMode.loop); - await warmUpPlayer.play(UrlSource('assets/warmUp.mp3')); + await warmUpPlayer.play(source); } Future _playWorkoutMusic() async { await warmUpPlayer.stop(); Future.delayed(const Duration(microseconds: 600)).then((value) async { + Source source = AssetSource('workout.mp3'); await workoutPlayer.setReleaseMode(ReleaseMode.loop); - await workoutPlayer.play(UrlSource('assets/workout.mp3')); + await workoutPlayer.play(source); }); } Future _intervalChange() async { - await AudioPlayer().play(UrlSource('assets/beep.mp3')); + Source source = AssetSource('beep.mp3'); + await AudioPlayer().play(source); } void _tick() { @@ -123,14 +128,16 @@ class _IntervalTimerPageState extends State { _currentDuration = _cooldownDuration; () async { await workoutPlayer.stop(); + Source source = AssetSource('cool_down.mp3'); await coolDownPlayer.setReleaseMode(ReleaseMode.loop); - await coolDownPlayer.play(UrlSource('assets/cool_down.mp3')); + await coolDownPlayer.play(source); }(); } else { () async { Future.delayed(const Duration(microseconds: 900)) .then((value) async { - await AudioPlayer().play(UrlSource('assets/finish.mp3')); + Source source = AssetSource('finish.mp3'); + await AudioPlayer().play(source); }); }(); _resetTimer();