1

I have followed the many helpful previous questions to get my AVPlayer successfully streaming video when my app goes to the background. There are two methods described on Apple's QA1668 and they both work for my stream urls.

The problem is that there is a noticeable audio gap during the transition that is identical for both methods. On my iPhone 6 in release mode I would say the gap is less than 0.5 seconds, which may not seem terrible but if I'm playing something like a music video this is very distracting.

After more testing it looks like this gap actually occurs when I remove the AVPlayerLayer (or, if I am using the other method, when I disable the AVMediaCharacteristicVisual tracks) as I have determined it will still happen if I hook those actions up to a button rather than the backgrounding state.

My guess is that is has something to do with the audio re-syncing to the new video state of the AVPlayer but really I have no clue. Any help would be greatly appreciated!

Nick Kruge
  • 11
  • 2
  • Did you ever figure this out? – user3344977 Sep 20 '15 at 04:43
  • When Apple Music came out this year, they added videos. When the videos minimize they are no longer visible and at this transition point the same audio gap is noticeable. Considering it happens to them I don't think there is a way around it. – Nick Kruge Sep 21 '15 at 17:48
  • Actually, I just tried it now on iOS 9 and they have fixed the bug for Apple Music. – Nick Kruge Sep 21 '15 at 17:51
  • That's too bad I was just going to join Apple Music to see the bug. Did you ever figure this out for yourself? Here's what I'm experiencing right now: http://stackoverflow.com/q/32675855/3344977 – user3344977 Sep 21 '15 at 17:52
  • Sorry, I keep pressing enter not meaning to actually post the comment. Please check out this article: https://www.objc.io/issues/23-video/core-image-video/ under "Getting Pixel Data From A Movie File". If you implement this to draw your own video frames rather than using an AVPlayerLayer, you won't have the problem with the audio gap. This was ultimately how I removed the gap for iOS 8. Because the frame drawing relies on a CADisplayLink, it stops drawing when the app is in the background. It seems possible iOS 9 has things fixed, so check that out first and let us know :) Good luck! Nick – Nick Kruge Sep 21 '15 at 17:55
  • Awesome thank you I will try to implement the fix from that article. Last thing, do you remember if your audio gap, was the audio ahead of the video or was the video ahead of the audio? – user3344977 Sep 21 '15 at 18:17
  • It was pretty hard to tell, but I believe the audio stopped and restarted right where it has stopped after the gap, meaning that the audio and video together was playing slightly ahead of the audio alone. However, the gap could have also just been due to something internal as far as I know. – Nick Kruge Sep 22 '15 at 19:44

0 Answers0