MPVolumeView在启动时不显示路线按钮 [英] MPVolumeView does not show route button on launch

查看:320
本文介绍了MPVolumeView在启动时不显示路线按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 9.1 - iPhone 6S

iOS 9.1 - iPhone 6S

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

MPVolumeView's route button (airplay) is not showing when app launches even when there are wireless routes available.

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

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.

我的应用程序中的MPVolumeView用于控制从UIWebView播放的视频量。此外,每当我激活无线路由进行流式传输时,MPVolumeView滑块都会消失 - 有没有办法在使用UIWebView播放媒体时阻止此行为?

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?

以下是我的代码创建MPVolumeView:

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];
}


推荐答案

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

As @kvr said, first test on hardware device

当有多条路线可用时,会出现Airplay路线按钮。

Airplay route button appears when more than one route is available.

欺骗我找到了永久显示Airplay按钮是隐藏MPVolumeView路线按钮,删除用户MPVolumeView用户交互并使用UIButton Wrapper定位路线按钮操作。

Trick I found to show permanently Airplay Button is to hide MPVolumeView route button, remove user MPVolumeView user interaction and target the route button action with a 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)
}

这篇关于MPVolumeView在启动时不显示路线按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆