当按下按钮时,我正在制作一个简单的iPad应用程序来播放电影.电影播放,电影结束时我想关闭AVPlayerView,然后返回主屏幕.目前,当视频完成时,它将保留在最后一帧.我的ViewController.Swift此刻.
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
//MARK : Properties
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
//MARK: Actions
@IBAction func playButton(_ sender: AnyObject) {
let movieURL = Bundle.main.url(forResource: "ElephantSeals", withExtension: "mov")!
let player = AVPlayer(url: movieURL as URL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
// player.actionAtItemEnd = playerViewController.dismiss(animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我认为actionAtItemEnd中可能存在某些内容,但我不确定如何实现它.谢谢.