Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVPlayerItemStatus.failed #213

Closed
ghost opened this issue Jun 27, 2019 · 25 comments
Closed

AVPlayerItemStatus.failed #213

ghost opened this issue Jun 27, 2019 · 25 comments
Labels
platform-ios Affects the ios platform

Comments

@ghost
Copy link

ghost commented Jun 27, 2019

Much like this issue: #62

Playing audio files from a remote URL on iOS (Simulator and device) fails with the error: AVPlayerItemStatus.failed

@kennenfromchina
Copy link

kennenfromchina commented Jul 3, 2019

Add following code to your Info.plist

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

to make your app load an HTTP URL.
https://stackoverflow.com/questions/30731785/

@luanpotter
Copy link
Member

Thanks for the response, @kennenfromchina :)

This is already mentioned in our readme, under "iOS App Transport Security"

So I'll close this, please let us know if any other problems arise o/

@ghost
Copy link
Author

ghost commented Jul 10, 2019

I have that in my info.plist already :) I think adding more verbosity on the error message will help find a solution.

@luanpotter
Copy link
Member

Ok, reoping then. I'm not sure what or who is throwing this error. This needs to be investigated further.

@luanpotter luanpotter reopened this Jul 10, 2019
@chenft
Copy link

chenft commented Oct 28, 2019

change androidEncoder, such as AndroidEncoder.HE_AAC

@jj-hoeksema
Copy link

I had the same problem, fixed it by using the correct path to the sound file, so recommend to check that again.

@CristianSavin
Copy link

@darren-f5s
Recently I also had a problem, but the problem was with local MP3.
Solution is that: When you call method play you need to provide an option isLocal: true, that solved my problem.

In your case you have to set isLocal: false.

@Debsuv
Copy link

Debsuv commented Jan 2, 2020

I am facing the same issue. I tried on Android and iOS and it is not working at all.

I gave this in my iOS plist

<key>NSAppTransportSecurity</key>
    	<dict>
    		<key>NSAllowsArbitraryLoads</key>
    		<true/>
    		<key>NSAllowsArbitraryLoadsInWebContent</key>
    		<true/>
    	</dict>

I enabled Log for Audio Player and also, I logged the events as well. It comes as this

flutter: result is ----> 1
flutter: Tihs is the state ---> AudioPlayerState.PLAYING
flutter: _platformCallHandler call audio.onError {playerId: 7491df87-db45-4b6f-86ca-42e63552e27e, value: AVPlayerItemStatus.failed}
flutter: Tihs is the state ---> AudioPlayerState.STOPPED
flutter: Tis is the error ---> AVPlayerItemStatus.failed

Flutter Doctor -v results

[✓] Flutter (Channel beta, v1.12.13+hotfix.6, on Mac OS X 10.14.6 18G103, locale en-IN)
• Flutter version 1.12.13+hotfix.6 at /Users/769969/Documents/flutter
• Framework revision 18cd7a3601 (3 weeks ago), 2019-12-11 06:35:39 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• CocoaPods version 1.8.4

[✓] Connected device (3 available)
• iPad Air • FEA6DF6D-7880-4519-B735-C516F830C381 • ios • com.apple.CoreSimulator.SimRuntime.iOS-11-0 (simulator)
• Chrome • chrome • web-javascript • Google Chrome 79.0.3945.88
• Web Server • web-server • web-javascript • Flutter Tools

The music url is http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1xtra_mf_p
I am loss to realise what is causing this error. I have awaited for the audio to play and it never does. I have checked the audio file in the web and it plays, so I cant figure what is wrong.

This is the way I am playing the audio file


  playTheAudio() async {

    final result = await advancedPlayer.play(kUrl, isLocal: false);

    debugPrint(" result  is ----> " + result.toString());
  }

in my pubspec.yaml I have added audioplayers: only so that the latest version plays.

@joseluissb
Copy link

joseluissb commented Jan 2, 2020

Hello, I have also the same problem as @Debsuv and @darren-f5s. The only further information I can add to what is have been already said is that the error seems to depend either on the format of the URL or the headers the server is using to distribute the audio file. I have this suspicion because I was able to make the same mp3 file to work or not depending if it was stored in a plain public bucket or a more complex link with autogenerated URL security key. For Android it worked in all cases.

@DaYuClo
Copy link

DaYuClo commented Feb 27, 2020

Any update on this? I am able to play all my audio on Android but on iOS it will fail to load 30% of the time. I am getting my audio files from the Google server which is HTTPS.

@matitalatina
Copy link

I just realized that iOS can't open correctly an audio file if you don't provide the right extension.
I was saving locally the file without extension, now I'm saving with it and it works even in iOS.

@joseluissb
Copy link

@matitalatina I can confirm, we solved this error in iOS by specifying the extension on the remote file link too, not only locally. Now streaming also works.

@HugoHeneault
Copy link
Contributor

I also resolved this issue by restarting my iPhone... If filepath & permissions are OK you might have a try!

@muarachmann
Copy link
Contributor

In my own case, this occurs when I am not connected to the internet. I noticed my WiFi got disconnected while streaming songs from remote url and of a sudden began logging this error maybe that could be yours else everything works fine when online

@kbanta11
Copy link

@matitalatina I can confirm, we solved this error in iOS by specifying the extension on the remote file link too, not only locally. Now streaming also works.

I fear this is why it will not work for me, but adding the extension seems to break even files that were playing before. I'm trying to play from Firebase storage links, will that make it not possible with access restrictions to actually link to the file with the extension?

What's weird is that iOS will play some shorter (< 10 seconds) files just fine if recorded on an Android (encoding: AAC), but not files longer than that. It will play a file recorded and uploaded from iOS just fine no matter the length. I'm recording and uploading the iOS files as '.m4a' and uploads from android recordings as '.mp3'.

I also didn't used to have this problem (~6 months ago), but just revived an old project and noticed this happening now.

@leafney
Copy link

leafney commented Jun 22, 2020

Thanks to @matitalatina and @joseluissb . I encountered the same error. Then I checked my code again and found that the file extension was wrong set .aac to .acc:

filePath = '${tmpDir.path}/$tmpFileName.acc';

@kbanta11
Copy link

@matitalatina I can confirm, we solved this error in iOS by specifying the extension on the remote file link too, not only locally. Now streaming also works.

You mentioned you solved this problem when pulling files with URLs from a Google server? Can you expand a little bit on what you had to do for this? I can't seem to get this to work, even if I add the file extension (which isn't always the same, so eventually I'll have to find a way to determine this from the file, but right now I'm just trying by hardcoding the file extension to the URL in the my play() function.

For reference I'm trying to play files from Firebase storage, and the url's don't seem to have an extension on them either

@SuMitVayuz
Copy link

final result = mediaBox.containsKey(url)
? await _audioPlayer.play(mediaBox.get(url),
position: playPosition, isLocal: true)
: await _audioPlayer.play(url, position: playPosition);
if (result == 1) setState(() => _playerState = PlayerState.playing);

I'm playing local files if it is available and if it's not then playing from the remote file. Its working fine in android but in ios, a remote file is being played but when playing local file it is giving the AVPlayerItemStatus.failed error.

Any help will be great.

@erickzanardo
Copy link
Member

This issue is outdated or uses a very old version of the project, could you please test if this happens on newer versions? And in case that this still happens, open a new issue?

@kuwaitbinary
Copy link

kuwaitbinary commented Aug 31, 2021

The problem happened to me when I started screen recording application called "Capto" to record screen and capture computer audio with Simulator audio of iOS. The fix was just restarting iOS simulator

@darkeronce
Copy link

darkeronce commented Jul 7, 2022

I'm facing the same error I try with version 0.20.* and now I'm trying with 1.0.1 that also give me the same problem
Unhandled Exception: AVPlayerItem.Status.failed
I'm on a iOS emulator and I'm using this url https://vibrey-bucket.s3.amazonaws.com/public/1b796d2b-1f04-411f-a9ba-bb03636a0b64.aac
I don't know if it is the format or another thing but never go throw then method so something is making trouble in iOS works just fine in android the problem is iOS

thanks in advance for any suggestion

ps: @luanpotter this isnt close yet please reopen

@azmathr
Copy link

azmathr commented Dec 28, 2022

Here is the code I am using:

child: TextButton( onPressed: () { final player = AudioPlayer(); player.play(DeviceFileSource( 'assets/note1.wav')); // will immediately start playing },

And I get the error code:
Syncing files to device iPhone 14 Plus... flutter: Unexpected platform error: AVPlayerItem.Status.failed

Latest Audioplayers version

@FXschwartz
Copy link

Same issue, on iOS only I get the AVPlayerItem.Status.failed when trying to play a file stored on the device.

Confirmed it exists before attempting to play the file.

@timefordroids
Copy link

That's how I solved the problem

Example 1. Fails with the error: AVPlayerItemStatus.failed
await player.setSourceDeviceFile(sound.audio);
player.play();

Example 2. Works like a charm
await player.setSourceAsset(sound.audio);
player.play();

@FaizanAhmad127
Copy link

FaizanAhmad127 commented Feb 25, 2023

For me, I was using mp3 as contentType in metadata of a file and saving it to the firebase cloud storage, replaced it with .aac and it started working.

final path='xyz.aac'; // previously was 'xyz.mp3'
final storageRef = FirebaseStorage.instance.ref().child(path);
final metadata = SettableMetadata(contentType: mime(path));  // mime_type is a package
final result = await storageRef.putData(data, metadata);

@Gustl22 Gustl22 added the platform-ios Affects the ios platform label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-ios Affects the ios platform
Projects
None yet
Development

No branches or pull requests