我正在制作一个简单的 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)
}
}
如您所见,我认为actionAtItemEnd 中可能有一些东西,但我不确定如何实现它。谢谢你。