audioplayers
audioplayers copied to clipboard
Unhandled Exception: AVPlayerItem.Status.failed
Using audioplayers package in a flutter app throws an exception on IPad Pro (4th gen) IOS 15.5. The audio playing is normal at first. After a few times playing from a source, audio stops playing and the following exception gets thrown.
Exception
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: AVPlayerItem.Status.failed
#0 MethodChannelAudioplayersPlatform._doHandlePlatformCall (package:audioplayers_platform_interface/method_channel_audioplayers_platform.dart:174)
#1 MethodChannelAudioplayersPlatform.platformCallHandler (package:audioplayers_platform_interface/method_channel_audioplayers_platform.dart:147)
#2 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:404)
#3 MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:397)
#4 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:380)
#5 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:377)
#6 _invoke2.<anonymous closure> (dart:ui/hooks.dart:190)
#7 _rootRun (dart:async/zone.dart:1426)
Versions
- audioplayers: ^1.0.1
- Dart 2.17.5
- Flutter 3.0.4
Everything works just fine on my android devices.
Flutter code used to play the sounds
class SoundPlayer {
final _audioPlayer = AudioPlayer();
void playSound(AudioPlayEnum audioPlay) {
if (audioPlay == AudioPlayEnum.correct) {
_audioPlayer.play(AssetSource('sounds/correct.mp3'), volume: 1.0);
}
if (audioPlay == AudioPlayEnum.wrong) {
_audioPlayer.play(AssetSource('sounds/wrong.mp3'), volume: 1.0);
}
if (audioPlay == AudioPlayEnum.select) {
_audioPlayer.play(AssetSource('sounds/select.mp3'), volume: 1.0);
}
}
}
+1
Happens when running an app on a Simulator. Latest Xcode, latest Flutter stable channel.
I wonder if there's any feedback on this bug?
+1
Happens when running an app on a Simulator. Latest Xcode, latest Flutter stable channel.
Have you checked with physical devices, also which platform?
I didn't check with a physical device yet. The platform is macOS Monterey x64 (MBP 16").
It also happens on a physical device (audioplayers: ^1.0.1 / iPhone 12 mini)
same here audioplayers: 1.0.1, iPhone 13 Pro(iOS 15.5)
@AriDevC seems to be happening on real devices…
I think it will be fixed this problem use with playerId.
final player = AudioPlayer(playerId: "test");
player.play(file);
same problem here
This happens when the file doesn't exist.
final file = 'file:///Users/tmp/asdf.m4a';
final player = AudioPlayer(playerId: "test");
if (File(source).existsSync()) {
player.play(file);
}else{
print('file not exists');
}
I'm having the same issue with IOS - Running on android studio chipmunk 2021.2.1 Patch 1, iPhone 11 Pro Simulator (IOS 15.5), Flutter 2.10.5 (stable).
Attempting to play an audio file from firebase storage URL. Works fine on Android simulators.
Hey community, can you help out with a Pull Request here? It's easier than you think. We are lacking of ios / mac devices :)
Is anyone working on this? Can I go for it?
I can't replicate this. Using Flutter 3.0.5, iOs 16.0, Dart 2.17.6. I'm downloading iOs 15.5 and I'll see if I can replicate that
Any update on this @lucagonzalez ?
any updates?
same error, any update?
+10
I published an app to the app store back then with this bug. All the sounds in the app worked just fine. So I think you guys don't have to worry much until it's fixed.
Have the same issue, and I've confirmed that the file exists before attempting to play. I've tried setting the source initially on load and then using the resume method, as well as just calling the play() method with the file path passed in. Both fail.
This only happens when I attempt to play a file saved to the device, if I try to play a file from the flutter assets, then it plays just fine.
This is on iPhone 14 Pro Max v16.1.2 Works just fine on Android
For me, I've noticed that the official example was working on my Mac while my code wasn't, as per https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md#unsafe-http-when-playing-remote-urls, I added necessory entry in Info.plist as well, but it still didn't make any progress So I created a new empty project and decided to compare my code with the offcial code manually, finally, I found that the following files of the offcial example has one more entry than mine: macos/Runner/Release.entitlements, macos/Runner/Release.entitlements By adding following lines in both file:
<key>com.apple.security.network.client</key>
<true/>
the issue finally gets solved
also worth noticing is that you have to provide correct url to play, if the url is incorrect, will encounter the same error https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md#other-errors-when-playing-remote-urls
UPDATE: iOS: just add following into ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
For me, I've noticed that the official example was working on my Mac while my code wasn't, as per https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md#unsafe-http-when-playing-remote-urls, I added necessory entry in Info.plist as well, but it still didn't make any progress So I created a new empty project and decided to compare my code with the offcial code manually, finally, I found that the following files of the offcial example has one more entry than mine: macos/Runner/Release.entitlements, macos/Runner/Release.entitlements By adding following lines in both file:
<key>com.apple.security.network.client</key> <true/>
the issue finally gets solved
also worth noticing is that you have to provide correct url to play, if the url is incorrect, will encounter the same error https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md#other-errors-when-playing-remote-urls
UPDATE: iOS: just add following into ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key> <dict> <!--Include to allow all connections (DANGER)--> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
I was hopeful, but unfortunately, this didn't fix the issue for me. It's very odd that this package worked just fine a couple of months ago.
I confirm the file exists on the device - _recordingFilePath: /var/mobile/Containers/Data/Application/48712F32-4D83-48AE-A971-6C1C1D531A55/Documents/goalAudio.aac
But then when it goes to play the file with the same file path I get flutter: Unexpected platform error: AVPlayerItem.Status.failed
On iOS only which makes me think it's some kind of permission issue?
I have been trying to figure out why I have been getting this error for a few months now when trying to play certain Asset files on my iPhone 8 (works fine on Android).
flutter: Unexpected platform error: AVPlayerItem.Status.failed
For me it only happened on one or two of my audio files, but not the rest. The only difference between them was that the ones that worked were .wav
files, which I created and exported from Audacity, and the ones that didn't work were .mp3
file, which I got from a coworker who sent them from his phone over Discord.
I finally realized that the original audio files that my coworker had sent me were actually .m4a
file extension, but when I downloaded them from Discord it "converted" them to .mp3
which must have somehow corrupted them or something. Even other audio processing software wouldn't open up the converted .mp3
files.
Ultimately I fixed the problem by removing the .mp3
files from the project, and having my coworker AirDrop the original audio files to me, which preserved the .m4a
extension. When I added these to the project and played the asset with the correct file extension it worked like a charm.
final audioPlayer = AudioPlayer();
audioPlayer.setSourceAsset('audio/sound_effect.m4a');
audioPlayer.resume();
I'm not sure if this is what other people are dealing with, but it finally fixed the issue for me. If you are getting your audio from the internet somehow, check and make sure then the download process isn't changing the file extension.
I have been trying to figure out why I have been getting this error for a few months now when trying to play certain Asset files on my iPhone 8 (works fine on Android).
flutter: Unexpected platform error: AVPlayerItem.Status.failed
For me it only happened on one or two of my audio files, but not the rest. The only difference between them was that the ones that worked were
.wav
files, which I created and exported from Audacity, and the ones that didn't work were.mp3
file, which I got from a coworker who sent them from his phone over Discord.I finally realized that the original audio files that my coworker had sent me were actually
.m4a
file extension, but when I downloaded them from Discord it "converted" them to.mp3
which must have somehow corrupted them or something. Even other audio processing software wouldn't open up the converted.mp3
files.Ultimately I fixed the problem by removing the
.mp3
files from the project, and having my coworker AirDrop the original audio files to me, which preserved the.m4a
extension. When I added these to the project and played the asset with the correct file extension it worked like a charm.final audioPlayer = AudioPlayer(); audioPlayer.setSourceAsset('audio/sound_effect.m4a'); audioPlayer.resume();
I'm not sure if this is what other people are dealing with, but it finally fixed the issue for me. If you are getting your audio from the internet somehow, check and make sure then the download process isn't changing the file extension.
Unfortunately, I tried all different file extension types. The only thing that worked for me was having to switch to the flutter_sound package and downgrade to several major versions.
It's very odd that every sound-playing package I've tried has the same issue.
For me, this issue happened in both the simulator and on a real device when playing from an asset file, both mp3 and m4a. Turns out I had some spaces in my sound filename, removing the spaces fixed it on both the sim and real device.
Closing in favor of #1494