Been trying to solve this issue for 2 days now and I give up. Im trying to implement a customized airplay button (I have to beacuse the background is white and the button must be black). Ive added a view in interfacebuilder and chose mpVolumeView for it. Then I made the connections and wrote the following code;
viewDidLoad.. {
.....
[_volumeView setShowsVolumeSlider:NO];
for (UIButton *button in _volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
[button setImage:[UIImage imageNamed:@"airplay_icon.png"] forState:UIControlStateNormal];
[button addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
[button addTarget:self action:@selector(switchAirplayButton) forControlEvents:UIControlEventTouchUpInside];
[button sizeToFit];
}
}
[_volumeView sizeToFit];
}
-(void)switchAirplayButton {
for (UIButton *button in _volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
NSLog(@"%d", _controlBar.player.airPlayVideoActive);
if(_controlBar.player.airPlayVideoActive) {
[button setImage:[UIImage imageNamed:@"airplay_icon_pressed.png"] forState:UIControlStateNormal];
} else [button setImage:[UIImage imageNamed:@"airplay_icon.png"] forState:UIControlStateNormal];
[button sizeToFit];
}
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([object isKindOfClass:[UIButton class]] && [[change valueForKey:NSKeyValueChangeNewKey] intValue] == 1) {
[(UIButton *)object setImage:[UIImage imageNamed:@"airplay_icon.png"] forState:UIControlStateNormal];
[(UIButton *)object sizeToFit];
}
}
The "player" is a singelton based on AVPLayer. However, it always returns false when checking if airPlay is active. Maybe it's just beacuse im using sound, not video.
So my question is, how could I change the button to... lets say an orange one (just to match the rest of the interface) when airplay is streaming (just like apple is making it blue). I have tried everything and it's just not working at all. Please help me.