迅速。如何删除AVPlayerViewController中的工具栏

时间:2016-02-07 12:18:51

标签: swift toolbar avplayer avplayerviewcontroller preroll

我正在使用AVPlayerViewController呈现AVPlayer,并在其中显示前贴片广告,但我想删除顶部和按钮栏,或者让用户无法在广告完成之前解除ViewController

Screnshot from iphone

我该怎么做?

这是我的AVPlayerViewController实现的代码:

let preRollAdPlayer = AVPlayerViewController()

let player = AVPlayer()
preRollAdPlayer.player = player
if #available(iOS 9.0, *) {
    preRollAdPlayer.delegate = self
}

preRollAdPlayer.showsPlaybackControls = false

self.view?.window?.rootViewController?.presentViewController(preRollAdPlayer, animated: true, completion: {
    self.preRollAdPlayer.playPrerollAdWithCompletionHandler({ (error) -> Void in

        if (error != nil) {
            NSLog("Error Message: %@", error)
        } else {
            print("preRoll loaded")
        }

        self.preRollAdPlayer.dismissViewControllerAnimated(true, completion: {
            if (error != nil) {
                NSLog("Error Message: %@", error)
            }
        })
    })

})

1 个答案:

答案 0 :(得分:0)

根据Apple的说法,您应该使用showsPlaybackControls属性:

  

一个布尔值,指示播放器视图控制器是否显示播放控件。

将其设为false:

<强>夫特:

yourAvPlayer.showsPlaybackControls = false

目标C:

[yourAvPlayer setShowsPlaybackControls:FALSE];