AVAudioPlayer and AirPlay - maybe?

I am trying to figure out if it is possible to switch AirPlay support using the AVAudioPlayer class.

From what I read:

AirPlay is a technology that allows your application to stream audio to Apple TV and third-party speakers and AirPlay receivers. AirPlay support is built into the AV Foundation and the Core Audio family of frames. Any audio content that you play using these frameworks automatically gets the right to distribute AirPlay. After the user wants to play audio using AirPlay, he is automatically routed by the system. [ Ref ]

Based on this information; It should work with AVAudioPlayer, as it is part of the AVFoundation ; but I can’t find documentation supporting this assumption.

I also found some documentation that says that this can be done using MPMoviePlayerViewController :

Support for playing videos using AirPlay is included in the MPMoviePlayerController class. This support allows you to play video content on AirPlay-enabled equipment such as Apple TV. If the allowsAirPlay property of the active allowsAirPlay object MPMoviePlayerController set to YES and the device is in the range of hardware supported by AirPlay, the video player provides the user with a control for sending video to this equipment. [ Ref ]

There seems to be some conflicting information here. Does anyone know if AVAudioPlayer can be used to route to AirPlay or are we forced to use the MPMoviePlayerController class?

Thank you very much.

+4
source share
2 answers

In response to my own question. It seems like a simple way is to add the custom volume control mentioned here: [ ref ], and it works great with MPAudioPlayer . It is just a matter of positioning it.

+2
source

Its pretty easy with Interface Builder so you can easily use Auto Layout. Place the UIView object anywhere in your main view, then subclass MPVolumeView and use this custom class for your UIView object

enter image description here

and subclass of class VolumeView MPVolumeView

 import UIKit import MediaPlayer class VolumeView: MPVolumeView { convenience init() { self.init() } override func drawRect(rect: CGRect) { self.showsVolumeSlider = false self.layer.cornerRadius = 10.0 self.clipsToBounds = true } 

}

0
source

All Articles