audioplayers
audioplayers copied to clipboard
Audio played with 'AudioCache' is delayed the first time even if preloaded.
The first time audio is played with AudioCache, even if IAudioCache.loadAll is used beforehand, is played with a slight delay; second and further attempts do not have any delay.
Description
It seems like loadAll or load are not enough the first time. A possible workaround would be to play each sound with volume set to 0 to 'worm up', but it is a pretty ugly hack.
Code to Reproduce
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await initPlayer();
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: TextButton(
onPressed: playAlarm,
child: Text('Play'),
),
),
),
);
}
}
// ----------
const _timerAlarmAudioFile = 'timer_alarm.mp3';
late final AudioCache _audioCache;
Future<void> initPlayer() {
_audioCache = AudioCache(
prefix: 'assets/audio/',
fixedPlayer: AudioPlayer(),
);
return _audioCache.loadAll([_timerAlarmAudioFile]);
}
void playAlarm() {
_audioCache.play(_timerAlarmAudioFile, mode: PlayerMode.LOW_LATENCY);
}
Platforms
- iPhone Xs + iOS 14.5.
- Pixel 3XL + Android 11.
- Flutter version 2.2.1 stable channel.
- audioplayers version: 0.19.0
- App run in release mode run with the following command:
flutter run --release -d <device id> - The sound I'm playing is this: https://www.zedge.net/ringtone/99a9a13c-2881-32ff-aa8b-84302fb3532c
same here, I'm trying to get sounds to seamlessly run one after the other, but there is this delay..
I have the same issue, the player cannot play a sound instantly even if the needed sound is preloaded using AudioCache
I also had the same problem
I'm also facing the same problem
Can you retest with audioplayers: ^1.1.0 ?
Marking as stale. May have a look at #1469 or we may need to replace the Android implementation with ExoPlayer. Feel free to open a new issue with current AP version.