bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.01k stars 845 forks source link

Unable to play sound, I want to achieve fast repetitive beeps about 16ms time interval #1795

Open Pr47h4m opened 6 months ago

Pr47h4m commented 6 months ago

Checklist

Current bug behaviour

Was working fine in version < 6.0.0

Beeps are not played

Expected behaviour

Repeated sound (beep) should be played

Steps to reproduce

Approach to play fast repetitive beeps I am creating List readyPlayers where I am initialising and storing about (120) players in this list so whenever activity starts app has to play beep every second and beeps should be always continuous during the activity this is done by popping 1 player instance from readyPlayers list and playing beep using it and when player complete the beep it is seek to 0 position and again added to ready players list

  1. Execute flutter run on the code sample
  2. code a. Beeper.instance.init(); b. await for(int i = 0; i < 100; ++i) await Future.delayed(const Duration(milliseconds: 16), () => Beeper.instance.beepSoft()); c. or Timer.periodic(const Duration(milliseconds: 16), (_) => Beeper.instance.beepSoft());
  3. Audio is not played

Code sample

Code sample ```dart import 'package:audioplayers/audioplayers.dart'; class Beeper { final _beepSoft = 'audios/beep_soft.mp3', _beepSharp = 'audios/beep_sharp.mp3', _beepBackground = 'audios/beep_background.mp3'; static final Beeper _instance = Beeper._(); static Beeper get instance => _instance; final sw = Stopwatch()..start(); Beeper._(); List readyPlayers = []; void init() async { AudioLogger.logLevel = AudioLogLevel.error; final audioCache = AudioCache.instance; await audioCache.loadAll([_beepSoft, _beepSharp, _beepBackground]); for (int i = 0; i < 120; i++) { final audioPlayer = AudioPlayer(); audioPlayer.audioCache = audioCache; await audioPlayer.seek(const Duration(milliseconds: 20)); audioPlayer.onPlayerComplete.listen((event) async { await audioPlayer.seek(Duration.zero); readyPlayers.add(audioPlayer); }); readyPlayers.add(audioPlayer); } } void beepSoft() async { if (sw.elapsedMilliseconds < 36) { return; } sw.reset(); if (readyPlayers.isEmpty) { return; } final ap = readyPlayers.last; readyPlayers.removeLast(); await ap.play(AssetSource(_beepSoft)); } void beepSharp() async { if (sw.elapsedMilliseconds < 36) { return; } sw.reset(); if (readyPlayers.isEmpty) { return; } final ap = readyPlayers.last; readyPlayers.removeLast(); await ap.play(AssetSource(_beepSharp)); } void beepBackground() async { if (sw.elapsedMilliseconds < 36) { return; } sw.reset(); if (readyPlayers.isEmpty) { return; } final ap = readyPlayers.last; readyPlayers.removeLast(); await ap.play(AssetSource(_beepBackground)); } } ```

Affected platforms

Android, iOS, macOS

Platform details

No response

AudioPlayers Version

6.0.0

Build mode

debug, profile, release

Audio Files/URLs/Sources

Archive.zip

Screenshots

No response

Logs

Full Logs Flutter doctor: ``` [✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB) • Flutter version 3.19.6 on channel stable at /Users/pr47h4m/development/sdks/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (8 days ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/pr47h4m/development/sdks/android • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/pr47h4m/development/sdks/android • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (3 available) • Pratham’s iPhone (mobile) • 00008120-00084C8A1107C01E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.79 [✓] Network resources • All expected network resources are available. • No issues found! ```

Related issues / more information

No response

Working on PR

no way