如何在VLC播放器上方快速添加全屏按钮

时间:2018-07-10 01:45:37

标签: ios swift vlc libvlc

我想在VLC视频播放器顶部全屏添加按钮。我尝试了此代码,但无法正常工作:

    class VideoScreen: UIViewController{

    @IBOutlet weak var playerView: UIView!
    @IBOutlet weak var indicator: UIActivityIndicatorView!
    @IBOutlet weak var btnFullSrc: UIButton!
    @IBOutlet weak var playerViewHeight: NSLayoutConstraint!

    var b : Bool = false;

    let player: VLCMediaPlayer = {
        let p = VLCMediaPlayer(options: ["--extraintf="])
        return p!
    }();

    override func viewDidLoad() {
        title = "Xem camera"

        self.initPlayer()
    }

    override func viewDidDisappear(_ animated: Bool) {
        player.stop()
    }

    func initPlayer() {
        let streamUrl = URL(string: rstpFactoryUrl)
        let media = VLCMedia(url: streamUrl)

        player.media = media
        player.delegate = self
        player.drawable = playerView

        player.play()
        (player.drawable as! UIView).bringSubview(toFront: btnFullSrc)
    }
}

这是我的情节提要UI:

enter image description here

当视频正在运行时,“ btnFullSrc”被隐藏,可能是视频帧始终在最上面。任何帮助都在这里

更新:我将代码更改为

self.view.bringSubview(toFront: btnFullSrc)

但仍然无法正常工作

2 个答案:

答案 0 :(得分:2)

您的按钮是视频视图的子视图。 VLCKit不支持此功能。您需要使按钮处于相同或更高的层次结构级别,才能在视频顶部显示。

答案 1 :(得分:0)

您的电流将VLC屏幕显示在最前面。 如果要将按钮置于最前面,则应执行以下操作:

self.view.bringSubview(toFront: btnFullSrc)

或执行以下操作:

playerView.bringSubview(toFront: btnFullSrc)