iOS 9.1 - iPhone 6S
MPVolumeView's route button (airplay) is not showing when app launches even when there are wireless routes available.
I have tried querying my MPVolumeView after it has been created to check for wireless routes and I get 0. I'm only able to get 1 (and have the route button appear) by disabling and enabling WiFi to trigger a notification.
The MPVolumeView in my app is to control the volume of videos played from UIWebView. Also, whenever I activate a wireless route for streaming the MPVolumeView slider disappears - is there a way to prevent this behaviour when using UIWebView to play media?
Below is my code for creating the MPVolumeView:
-(void) createAndDisplayMPVolumeView{
// Create a simple holding UIView and give it a frame
volumeHolder = [[UIView alloc] initWithFrame: volumeSlider.frame];
volumeHolder.autoresizingMask = UIViewAutoresizingFlexibleHeight;
volumeSlider.hidden = YES;
// set the UIView backgroundColor to clear.
[volumeHolder setBackgroundColor: [UIColor clearColor]];
// add the holding view as a subView of the main view
[nowPlayingMainView addSubview: volumeHolder];
// Create an instance of MPVolumeView and give it a frame
myVolumeView = [[CustomVolumeView alloc] initWithFrame: volumeHolder.bounds];
myVolumeView.tintColor = [UIColor darkTextColor];
myVolumeView.showsRouteButton = YES;
myVolumeView.showsVolumeSlider = YES;
volumeRect = myVolumeView.frame;
[myVolumeView setRouteButtonImage:[UIImage imageNamed:@"airplayButton"] forState:UIControlStateNormal];
[myVolumeView setRouteButtonImage:[UIImage imageNamed:@"airplayButtonHighlighted"] forState:UIControlStateHighlighted];
[myVolumeView setRouteButtonImage:[UIImage imageNamed:@"airplayButtonSelected"] forState:UIControlStateSelected];
[volumeHolder addSubview: myVolumeView];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…