Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating AirPlay to iOS app in Swift

I want to cast a radio stream through AirPlay (to an AppleTV). I've researched a lot related to this topic, but I found the documentation really poor.

This is the Apple documentation for AirPlay 2: https://developer.apple.com/documentation/avfoundation/airplay_2/getting_airplay_2_into_your_app

I found out that AVRoutePickerView is only available after iOS 11. Below iOS 11, MPVolumeView needs to be used.

I've checked the iOS version, integrated these classes, the cast is working, buy not how I want it

A black screen appears on the TV while playing and I can't control the volume of the cast.

Can anyone show me how to integrate AirPlay into an iOS app simple and clearly? Any help would be appreciated.

like image 681
anitteb Avatar asked Feb 20 '18 15:02

anitteb


1 Answers

The problem was I set on my AVPlayer object the allowsExternalPlayback to true. This property's "ancestor" in earlier versions of iOS (until 6.0), was more meaningful with the name of: allowsAirPlayVideo.

SO if you call this allowsExternalPlayback = false on your player, the black screen disappears and you can also control the volume of the radio cast.

like image 86
anitteb Avatar answered Oct 15 '22 16:10

anitteb