How to reduce cutoff when playing audio using airplay?
Asked Answered
F

1

11

When playing a sound from an iOS device connected to Apple TV via AirPlay (using iOS9.2), the first second or so of the sound playing is cut off. This unwanted behavior is not app specific, but system wide(eg. Apple's official apps have this bug too).

See https://forums.developer.apple.com/thread/28086

Is there a workaround where the full audio file can be played? For example adding blank sounds before playing the file? Or changing how the API is called? Or should I wait for Apple's official fix?

Foreyard answered 11/12, 2015 at 12:12 Comment(2)
You should wait for the fix anyhow. But consider this hack. If your audio doesnot sound for first two second, i.e add a blank audio of length two second to your original audio, such that the hiccup in sync between app and tv can be cheated. Use garage band for this. Or use threading in your app like GCD. dispatch_async for asynchronous operations.Stilbite
I just performed a test using the latest version (as of 20160217) of iOS 9.3 beta 3 (13E5200d). The cutoff only appears at the first time and not the subsequent audio playback. This contrasts to iOS 9.2 which occurs every audio playback.Senegal
J
0
  1. This issue does not appear to occur on any current iOS releases so my first suggestion is to upgrade.
  2. If you must use iOS 9.2 then I would suggest playing a blank audio file for 2 seconds then start your full audio file.

Sample code:

audioPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

[[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(playEnded:)
                                                   name:AVPlayerItemDidPlayToEndTimeNotification
                                                 object:[audioPlayer currentItem]];

- (void)playEnded:(NSNotification *)notification
{
    // Start the full audio file here
}
Jasik answered 25/12, 2016 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.