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

Failed to set source when try to play audio on IOS PHYSICAL DEVICE #1783

Open fabiojansenbr opened 7 months ago

fabiojansenbr commented 7 months ago

Checklist

Current bug behaviour

Im getting this error when try to play audio on IOS only in a physical device. On simulator works fine.

Runner(Flutter)[4087] : DeviceFileSource(path: /var/mobile/Containers/Data/Application/387E8E16-458F-4F36-80AB-C2152228C985/Documents/audios/audio17120075.m4a), Apr 1 20:40:44 Runner(Flutter)[4087] : PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl, null)<\M-b\M^@\M-

Expected behaviour

The audio should play properly

Steps to reproduce

  1. Execute flutter run on the code sample
  2. ...
  3. ...

Code sample

Code sample ```dart void main() { } ```

Affected platforms

iOS

Platform details

No response

AudioPlayers Version

5.2.1

Build mode

No response

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

my relevant logs
Full Logs ``` my full logs or a link to a gist ``` Flutter doctor: ``` Output of: flutter doctor -v ```

Related issues / more information

No response

Working on PR

no way

MuhammedMohsen1 commented 6 months ago

did you find solution ?

divya-BV commented 6 months ago

Any update on this? i am also facing the same issue

novas1r1 commented 6 months ago

Same issue but with ByteSource: Flutter 3.19.5 audioplayers 6.0.0 iOS: 17.4

"PlatformException (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))"

narendra-vaniya commented 6 months ago

I'm encountering the same error: PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://TROUBLESHOOTING_GUIDE, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null) This issue occurs when I attempt to play audio using BytesSource on iOS. Working on Android, but failing on iOS.

Flutter 3.19.6 audioplayers 6.0.0 iOS: 17.4

narendra-vaniya commented 6 months ago

@novas1r1 Have you found any solution?

novas1r1 commented 6 months ago

@narendra-vaniya nope, sorry. I switched to soundpool

Gustl22 commented 6 months ago

You may can add some files in order to have a chance to reproduce the problem. Best regards.

narendra-vaniya commented 6 months ago

@narendra-vaniya nope, sorry. I switched to soundpool

Thank @novas1r1

callmephil commented 2 months ago

I've found a solution, we must provide the mimeType.

Sample.

    await _audioPlayer.play(
      BytesSource(bytes, mimeType: 'audio/mp3'),
    );

It would be nice to handle this case directly within the BytesSource class if the mimeType is empty.

cristian1980 commented 1 month ago

I am having a similar issue but it seems to be kind of random. I made this change f15b414135039b72760a908b95c01aa8c9da6422 so I can see the error.

AudioPlayers Exception: AudioPlayerException(
    AssetSource(path: sounds/pop.wav, 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: Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo={NSLocalizedDescription=Cannot Complete Action, NSLocalizedRecoverySuggestion=Try again later.}, null)<…>

The error is: Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo={NSLocalizedDescription=Cannot Complete Action, NSLocalizedRecoverySuggestion=Try again later.

The code I used is loading about 30 tracks using this code, but the issue does not always occur.

_audioContext =AudioContextConfig(respectSilence: Platform.isIOS).build();

var player = AudioPlayer();
await player.setReleaseMode(ReleaseMode.stop);
await player.setAudioContext(_audioContext);
await player.setVolume(volume);
await player.setSource(AssetSource('sounds/$filePath'));