iOS 9.1 - iPhone 6S
MPVolumeView 的路由按钮(airplay)在应用程序启动时不显示,即使有可用的无线路由。
在创建 MPVolumeView 以检查无线路由后,我尝试查询它并得到 0。通过禁用和启用 WiFi 以触发通知,我只能得到 1(并显示路由按钮)。
我的应用程序中的 MPVolumeView 用于控制从 UIWebView 播放的视频的音量。此外,每当我激活用于流式传输的无线路由时,MPVolumeView 滑块就会消失 - 有没有办法在使用 UIWebView 播放媒体时防止这种行为?
下面是我创建 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];
}