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
1.93k stars 824 forks source link

Audiplayer failed to set DeviceFileSource: PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, Failed to set source. For troubleshooting, see " + "https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md) #1744

Open vaimikpatel2908 opened 5 months ago

vaimikpatel2908 commented 5 months ago

Checklist

Current bug behaviour

My code is as follows:

Future<void> startPlayer(String filepath) async {
    try {
 // For ex, filepath is getApplicationDocumentsDirectory().path+"/file.aac"
      final DeviceFileSource source = DeviceFileSource(filepath); 

        await _player?.play(source);
        } catch (e) {
      throw SoundPlayerException(e.toString());
    }
  }

But it still throws the PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, Failed to set source. For troubleshooting, see "

I have also copied the code from the demo/examples and tried to play the same file as well but no luck with both plugins.

If anyone has an idea, please guide me. I am clueless.

Currently works smoothly on Android but not on iOS

Expected behaviour

It should be working flawlessly on iOS as the same code works on Android

Steps to reproduce

No response

Code sample

No response

Affected platforms

iOS

Platform details

Xcode iOS simulator iPhone 15 Pro max(iOS 17.2) Physical device iPhone 12 pro (iOS 17.2.1)

AudioPlayers Version

5.2.1

Build mode

debug, release

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

No response

Related issues / more information

No response

Working on PR

no way

Ayush783 commented 3 months ago

same issue happening with me

HassanMalaabeh commented 3 months ago

It also throws the same error for me on IOS only on the latest version of the package audioplayers: ^6.0.0 while I already released the app on Android

void playAudio(){
    final audioRef = storage.ref().child(filePath);
    String url = await audioRef.getDownloadURL();

    await audioPlayer.play(DeviceFileSource(url)).onError((error, stackTrace) => throw Exception("Failed to play Local audio $error"));
  }

Error

flutter: \^[[31mAudioPlayers Exception: AudioPlayerException(
    DeviceFileSource(path: https://firebasestorage.googleapis.com/v0/b/APP_NAME-prod2.appspot.com/o/audios%2F6%2Ftitle.wav?alt=media&token=009a466f-894a-4b9c-944f-78056118a1b0, mimeType: null), 
    PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)<…>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Failed to play audio PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)
#0      AudioHelper.playLocal.<anonymous closure> (package:APP_NAME/helper/audio_helper.dart:13:83)
#1      FutureExtensions.onError.onError (dart:async/future.dart:1062:25)
#2      _RootZone.runBinary (dart:async/zone.dart:1666:54)
#3      _FutureListener.handleError (dart:async/future_impl.dart:177:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:850:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:871:13)
#6      Future._completeError (dart:async/future_impl.dart:651:5)
<asynchronous suspension>

Flutter doctor

[✓] Flutter (Channel stable, 3.19.2, on macOS 14.1.1 23B81 darwin-arm64, locale en-JO)
    • Flutter version 3.19.2 on channel stable at $HOME/develop/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (4 weeks ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at $HOME/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: $HOME/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • 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.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at $HOME/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.9+0-17.0.9b1087.7-11185874)

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.59

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Process finished with exit code 0
yogeshButani commented 2 months ago

It also throws the same error for me on IOS only on the latest version of the package audioplayers: ^6.0.0 while I already released the app on Android

void playAudio(){
    final audioRef = storage.ref().child(filePath);
    String url = await audioRef.getDownloadURL();

    await audioPlayer.play(DeviceFileSource(url)).onError((error, stackTrace) => throw Exception("Failed to play Local audio $error"));
  }

Error

flutter: \^[[31mAudioPlayers Exception: AudioPlayerException(
  DeviceFileSource(path: https://firebasestorage.googleapis.com/v0/b/APP_NAME-prod2.appspot.com/o/audios%2F6%2Ftitle.wav?alt=media&token=009a466f-894a-4b9c-944f-78056118a1b0, mimeType: null), 
  PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)<…>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Failed to play audio PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)
#0      AudioHelper.playLocal.<anonymous closure> (package:APP_NAME/helper/audio_helper.dart:13:83)
#1      FutureExtensions.onError.onError (dart:async/future.dart:1062:25)
#2      _RootZone.runBinary (dart:async/zone.dart:1666:54)
#3      _FutureListener.handleError (dart:async/future_impl.dart:177:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:850:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:871:13)
#6      Future._completeError (dart:async/future_impl.dart:651:5)
<asynchronous suspension>

Flutter doctor

[✓] Flutter (Channel stable, 3.19.2, on macOS 14.1.1 23B81 darwin-arm64, locale en-JO)
    • Flutter version 3.19.2 on channel stable at $HOME/develop/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (4 weeks ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at $HOME/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: $HOME/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • 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.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at $HOME/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.9+0-17.0.9b1087.7-11185874)

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.59

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Process finished with exit code 0

did you find the solution for this?? same issue here

crcdng commented 2 months ago

same here on macOS 14.4.1, Flutter 3.19.6, Flame 1.17.0, Flame Audio 2.10.1

flutter: AudioPlayers Exception: AudioPlayerException(
    AssetSource(path: explosion.mp3), 
    PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl, null)
Application finished.
flutter:
  assets:
    - assets/audio/explosion.mp3
Thread 1975:: com.apple.coremedia.audiomentor
0   libsystem_kernel.dylib              0x7ff80b398f7a 0x7ff80b395000 + 16250
1   CoreMedia                           0x7ff815c2240d 0x7ff815c03000 + 128013
2   CoreMedia                           0x7ff815c0d4c7 0x7ff815c03000 + 42183
3   MediaToolbox                        0x7ff81b316134 0x7ff81b118000 + 2089268
4   CoreMedia                           0x7ff815c20f08 0x7ff815c03000 + 122632
5   libsystem_pthread.dylib             0x7ff80b3d618b 0x7ff80b3d0000 + 24971
6   libsystem_pthread.dylib             0x7ff80b3d1ae3 0x7ff80b3d0000 + 6883

Thread 1976:: com.apple.coremedia.audioqueue.source
0   libsystem_kernel.dylib              0x7ff80b398f7a 0x7ff80b395000 + 16250
1   CoreMedia                           0x7ff815c2240d 0x7ff815c03000 + 128013
2   CoreMedia                           0x7ff815c0d4c7 0x7ff815c03000 + 42183
3   MediaToolbox                        0x7ff81b1ecf06 0x7ff81b118000 + 872198
4   CoreMedia                           0x7ff815c20f08 0x7ff815c03000 + 122632
5   libsystem_pthread.dylib             0x7ff80b3d618b 0x7ff80b3d0000 + 24971
6   libsystem_pthread.dylib             0x7ff80b3d1ae3 0x7ff80b3d0000 + 6883
adnan-haider007 commented 2 months ago

have you found any soluttion about this issue. i am also facing this issue. but i am facing this issue on using datatfilesource method.

Ayush783 commented 2 months ago

I don't know if this is the same usecase, I encountered this issue a while back. my usecase was recording and playing the audio. the recorded audio was getting encoded in .caf extension and I was trying to play it with .wav extension.

So you may want to check whether the audio is of proper format as you want t to be or not

adnan-haider007 commented 2 months ago

my recorded audio is wav format and tryy to play in same format, but still got error


    DeviceFileSource(path: /var/mobile/Containers/Data/Application/7F95E3F0-33DA-4637-8833-2E046A42CD5F/Documents/ISNSoundRecorder/1713940724904.wav), 
    PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl, null)<…>```

    i dont know why it behave like this
Ayush783 commented 2 months ago

@adnan-haider007 if you're using AudioRecorder then make sure to add .wav extension at the end of file path that you are passing to the start method. It gets recorded in .caf even if you specify AudioEncoder.wav explicitly.

If you're already doing it then can't help you sorry.

Nmxsz commented 1 month ago

I had the same issue and i faced maybe a weird bug?

I fixed it with this line of code before calling the AudioPlayer:

AudioCache.instance = AudioCache(prefix: '');

Im doing a Flutter App for web so i checked the network console and i saw an error getting my mp3 File

Request URL: http://localhost:60173**/assets/assets/**audio/wow_level_up.mp3 Request Method: GET Status Code: 404 Not Found

I wondered why the path includes the name assets twice because my implementation looks like this:

final audioPlayer = AudioPlayer(); await audioPlayer.play(AssetSource('audio/wow_level_up.mp3')); Maybe its a bug with the prefix thing i dont know.

Final result:

AudioCache.instance = AudioCache(prefix: ''); final audioPlayer = AudioPlayer(); await audioPlayer.play(AssetSource('audio/wow_level_up.mp3'));

Gustl22 commented 1 month ago

@Nmxsz see AudioCache. Having twice the assets directory for web is actually correct, assuming you have stored the file in the assets directory. See e.g. https://bluefireteam.github.io/audioplayers/assets/assets/nasa_on_a_mission.mp3

You will notice, if you run flutter build web and go to the folder, build/web, that all your assets are stored within an assets folder, and your folder named assets is a subdirectory of that. So you may made things worse, especially if you want things to work on other platforms other than web. If your files are stored within the audio folder on the root level, you probably did everything right.

For more infos, see this comment: https://github.com/flutter/flutter/issues/86833#issuecomment-1101891941

santtiagogp commented 1 month ago

@Nmxsz

I had the same issue and i faced maybe a weird bug?

I fixed it with this line of code before calling the AudioPlayer:

AudioCache.instance = AudioCache(prefix: '');

Im doing a Flutter App for web so i checked the network console and i saw an error getting my mp3 File

Request URL: http://localhost:60173**/assets/assets/**audio/wow_level_up.mp3 Request Method: GET Status Code: 404 Not Found

I wondered why the path includes the name assets twice because my implementation looks like this:

final audioPlayer = AudioPlayer(); await audioPlayer.play(AssetSource('audio/wow_level_up.mp3')); Maybe its a bug with the prefix thing i dont know.

Final result:

AudioCache.instance = AudioCache(prefix: ''); final audioPlayer = AudioPlayer(); await audioPlayer.play(AssetSource('audio/wow_level_up.mp3'));

This worked perfectly for me, thanks a lot!