在我的应用程序中,我会播放具有该功能的视频
func easyRandom_play(episodeTitle:String){
self.backgroundMusic?.stop()
backgroundMusic?.stop()
let link = "http://46.235.26.87/\(__TITLENAME_FOLDERNAME_DOWNLOAD__)/\(episodeTitle).m4v"
print(link)
let url:NSURL = NSURL(string: link)!
let player = AVPlayer(URL: url)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
现在无法停止视频 - 通常菜单按钮应该让我回来并结束播放。 有没有办法实现这个?
答案 0 :(得分:0)
您可以添加UITapGestureRecognizer
来处理菜单按钮。
override func viewDidLoad() {
// Setup Menu Button recognizer
let menuGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleMenuGesture(_:)))
menuGesture.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(menuGesture)
}
func handleMenuGesture(tap: UITapGestureRecognizer) {
print("Menu Gesture")
// Stop video and dismiss view controller here
}