4

Is it possible to do Airplay audio streaming like Spotify or Amazon Music. When i setup an Airplay stream with Audio from my App the screen (on the Apple-TV) turns black and shows only the progressbar.

Is it possible to show the small hint in the top corner with all the audio information which disappears after a few Seconds and don't block the whole Apple TV Ui?

Or is this kind of a Spotify / Amazon Music privilege?

ANE
  • 243
  • 1
  • 10
  • Have you considered using `MPNowPlayingInfoCenter`? – Mats Nov 27 '17 at 15:40
  • Using the `AVAudioPlayer` API with a local audio-only file yields the desired result when AirPlayed to an Apple TV. (i.e. The "now playing" notification appears, and no spurious black full-screen progress bar.) But `AVAudioPlayer`'s documentation says it does not work with streaming media. So I'm still trying to find a way to get `AVPlayer` to work with a streamed audio-only file. – Bill Feth Dec 07 '17 at 22:36
  • @BillFeth thanks for sharing your knowledge. Would be cool if you let me/us know when you make any progress on this topic. – ANE Dec 13 '17 at 12:27
  • @ANE, Spencer outlines a fairly succinct solution below. Please thumbs-up his response if you find it helpful as well. – Bill Feth Jan 10 '18 at 03:36

1 Answers1

0

We had this problem as well. I believe that there are some bugs here in Apple's court, but we found a decent workaround that seems to be pretty safe from side effects.

We found that setting the player's allowsExternalPlayback field to NO would sometimes correctly stream the audio without the blank video screen (along with correct display of the now playing information, correct response to volume rocker etc...). However, we found that very often it would fail to play anything at all.

Doing some runtime introspection, we found that the player would always correctly buffer from the network. But when it would hit the isPlaybackLikelyToKeepUp event, it would set the player's rate field to 1 indicating that it is playing, but more often than not, not actually play the audio. No errors were reported and so from all we could tell, the player itself thinks that it is indeed playing when it is not. We found this hangup to only occur when we had set an AirPlay device for audio output.

So we found that in certain event callbacks and other key places, if we added a simple one-liner:

if( self.avPlayer.rate == 1 ){ self.avPlayer.rate = 1; }

It would kick whatever internal hold ups were causing the player to not actually AirPlay and correctly stream the audio. If the player was already correctly playing, then no harm done.

  • _certain event callbacks and other key places_ What are these places? – anitteb Feb 21 '18 at 11:40
  • Places like the callbacks that are fired when buffers get received, playback state changes and the like. The idea is to just put the check in enough places that get executed often enough to quickly kick whatever is holding up the actual playback. – Spencer Nielsen Feb 22 '18 at 17:59