'iOS: Airplay picker MPVolumeView alternative
I'm using MPVolumeView to pick airplay device for avplayer airplay playback. Is there any possible non-private API alternative for doing this, so I would be able to provide my own UI Controls for picking airplay device?
By referring to the API, I mean, that all I need is:
- Ability to reroute audio to airplay-device specific audioRoute.
- Retrive airplay-device names. (get all available audioRoutes, then get descriptions for airplay audioRoutes)
I know AudioToolbox framework provides some additional API to deal AudioSession, but the only way I found to reroute audio is AVAudioSession's:
- (BOOL)overrideOutputAudioPort:(AVAudioSessionPortOverride)portOverride error:(NSError **)outError`
which only allows to reroute audio to build-in speakers. Maybe there is some other way how to achieve it there? (I also did only found the way how to retrieve the name of AirplayDevice as a description of the currentAudioRoute - Get name of AirPlay device using AVPlayer)
Solution 1:[1]
One should use AVRoutePickerView to manage all audio outputs
For instance, one can make subclass as follows
final class AMRoutePickerView: AVRoutePickerView {
override init(frame: CGRect) {
super.init(frame: frame)
translatesAutoresizingMaskIntoConstraints = false
tintColor = .clear
activeTintColor = .clear
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Here we hide visual content of this view by setting .clear.
Now one can put this view as top subview of any view or button from touchable UI.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | malex |
