audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Unhandled Exception: AVPlayerItem.Status.failed

Open arrowxpr opened this issue 2 years ago • 11 comments

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);
    }
  }
}

arrowxpr avatar Jul 10 '22 13:07 arrowxpr

+1

Happens when running an app on a Simulator. Latest Xcode, latest Flutter stable channel.

ndawod avatar Jul 10 '22 20:07 ndawod

I wonder if there's any feedback on this bug?

ndawod avatar Jul 12 '22 11:07 ndawod

+1

Happens when running an app on a Simulator. Latest Xcode, latest Flutter stable channel.

Have you checked with physical devices, also which platform?

arrowxpr avatar Jul 15 '22 23:07 arrowxpr

I didn't check with a physical device yet. The platform is macOS Monterey x64 (MBP 16").

ndawod avatar Jul 20 '22 11:07 ndawod

It also happens on a physical device (audioplayers: ^1.0.1 / iPhone 12 mini)

sunguard avatar Jul 26 '22 09:07 sunguard

same here audioplayers: 1.0.1, iPhone 13 Pro(iOS 15.5)

ktakayama avatar Jul 27 '22 13:07 ktakayama

@AriDevC seems to be happening on real devices…

ndawod avatar Jul 29 '22 11:07 ndawod

I think it will be fixed this problem use with playerId.

final player = AudioPlayer(playerId: "test");
player.play(file);

ktakayama avatar Jul 29 '22 13:07 ktakayama

same problem here

alihuseyin avatar Jul 29 '22 21:07 alihuseyin

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');
}

hectorAguero avatar Aug 04 '22 19:08 hectorAguero

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.

joabh avatar Aug 11 '22 07:08 joabh

Hey community, can you help out with a Pull Request here? It's easier than you think. We are lacking of ios / mac devices :)

Gustl22 avatar Sep 27 '22 18:09 Gustl22

Is anyone working on this? Can I go for it?

lucagonzalez avatar Oct 25 '22 17:10 lucagonzalez

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

lucagonzalez avatar Oct 25 '22 18:10 lucagonzalez

Any update on this @lucagonzalez ?

ndawod avatar Nov 10 '22 12:11 ndawod

any updates?

sajithlaldev avatar Nov 24 '22 11:11 sajithlaldev

same error, any update?

mzilaid avatar Dec 04 '22 13:12 mzilaid

+10

ndawod avatar Dec 12 '22 10:12 ndawod

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.

arrowxpr avatar Dec 12 '22 15:12 arrowxpr

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

FXschwartz avatar Jan 05 '23 21:01 FXschwartz

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>

hyan23 avatar Jan 12 '23 12:01 hyan23

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?

FXschwartz avatar Jan 19 '23 14:01 FXschwartz

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.

chandlery54 avatar Feb 01 '23 22:02 chandlery54

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.

FXschwartz avatar Feb 01 '23 23:02 FXschwartz

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.

mojo3344 avatar Apr 06 '23 20:04 mojo3344

Closing in favor of #1494

Gustl22 avatar May 07 '23 13:05 Gustl22