AVPlayer streaming audio not working with iOS9/Xcode 7

The following code is used to play streaming audio:


AVPlayer* avPlayer = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:urlString]];

avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

avPlayer.volume = 1.0f;

[avPlayer play];

When the avPlayer instance is queried I see:

avPlayer.status is "AVPlayerStatusReadyToPlay"

avPlayer.rate is 1

avPlayer.currentItem.playbackLikelyToKeepUp is FALSE

avPlayer.currentItem.playbackBufferEmpty is true

avPlayer.error is nil

avPlayer.muted is false


This code worked when compiled in XCode 6 and run on an iOS9 device. However, it has completely stopped working when the project was built with XCode 7. The audio never starts playing and I don't see any errors in the Xcode console.


Any ideas? Perhaps some security related to the user of HTML?

Replies

This code works fine when built with Xcode 7 and running on an iOS 8.4.1 device (iPhone 5). However, it does not work with an iOS 9.0.1 device (iPhone 6 Plus).

I have NOT found the solution to this issue yet. I've confirmed that 100% of my devices running iOS 9 (iPhone 6+, iPhone 5, iPad 2) with the app built with Xcode 7 have this issue (no audio). Additionally, I've confirmed that 100% of my devices (iPhone 4, iPhone 5, iPhone 6) running < iOS 9 when built with XCode 7 do NOT have this issue (audio works). I've also confirmed that 100% of my iOS 9 devices with app built with Xcode 6 do NOT have this issue (audio works).


I cannot be the only one seeing this. Apple how about chiming in here? It looks like Apple no longer supports streaming audio. That makes me sad. :-(


I'm installing Xcode 7.0.1 to see if this makes a difference.

Updating to Xcode 7.0.1 did not help.

This can be related with App Transport Security. Check this technote: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/


You may quickly check if your connection is really blocked by ATS. To do this modify your Info.plist as told on stackoverflow http://stackoverflow.com/a/32631639

Thanks Andrew, adding the info.plist content as described in http://stackoverflow.com/a/32631639 fixed my issue with AVPlayer on my iOS 9.0.2 iPhone 6.

Are you using NSURLProtocol in your app by any chance? I noticed that in iOS 9 AVPlayer is not using NSURLProtocol anymore. I'm setting security header in NSURLProtocol implementation and sience player is not using it my backend rejects streaming requests.

For anyone else that find this. (iOS 12) This fix only works on iOS >=10

I set:

avPlayer.automaticallyWaitsToMinimizeStalling = false;

and that allowed it to stream better for me.

I pulled it from:

https://stackoverflow.com/questions/50554270/avplayer-stops-playing-video-after-buffering