gpt4 book ai didi

ios - MPVolumeView 在启动时不显示路由按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:24:46 28 4
gpt4 key购买 nike

iOS 9.1 - iPhone 6S

即使有可用的无线路由,MPVolumeView 的路由按钮(airplay)也不会在应用程序启动时显示。

我在创建 MPVolumeView 后尝试查询它以检查无线路由,但我得到 0。我只能通过禁用和启用 WiFi 触发通知来获得 1(并显示路由按钮)。

我的应用程序中的 MPVolumeView 用于控制从 UIWebView 播放的视频的音量。此外,每当我激活用于流式传输的无线路由时,MPVolumeView slider 就会消失 - 在使用 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];
}

最佳答案

正如@kvr所说,先在硬件设备上测试

当有多个路由可用时,会出现 Airplay 路由按钮。

我发现永久显示 Airplay 按钮的技巧是隐藏 MPVolumeView 路由按钮,删除用户 MPVolumeView 用户交互并使用 UIButton Wrapper 定位路由按钮操作。

var airplayRouteButton: UIButton?

private func airPlayButton() -> UIButton {
let wrapperView = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
wrapperView.setImage(YOUR_AIRPLAY_IMAGE, for: UIControlState.normal)
wrapperView.backgroundColor = .clear
wrapperView.addTarget(self, action: #selector(PlayerView.replaceRouteButton), for: UIControlEvents.touchUpInside)

let volumeView = MPVolumeView(frame: wrapperView.bounds)
volumeView.showsVolumeSlider = false
volumeView.showsRouteButton = false
volumeView.isUserInteractionEnabled = false

self.airplayRouteButton = volumeView.subviews.filter { $0 is UIButton }.first as? UIButton

wrapperView.addSubview(volumeView)

return wrapperView
}

@objc private func replaceRouteButton() {
airplayRouteButton?.sendActions(for: .touchUpInside)
}

关于ios - MPVolumeView 在启动时不显示路由按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35925850/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com