我尝试使用Xcode 7.1播放本地视频。我想要的只是视频在视图和播放时加载全屏。
import UIKit
import AVFoundation
import AVKit
class myClass: AVPlayerViewController {
private func playVideo() {
if let path = NSBundle.mainBundle().pathForResource(“video”, ofType: "mp4") {
let url = NSURL(fileURLWithPath: path)
player = AVPlayer(URL: url)
player?.play()
}
else {
print("Oops, something wrong when playing video.mp4")
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
playVideo()
}
}
答案 0 :(得分:0)
我设法找到了解决办法。
import Foundation
import UIKit
import AVKit
class PlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func playVideo() {
if let path = NSBundle.mainBundle().pathForResource("video", ofType: "mp4") {
let url = NSURL(fileURLWithPath: path)
player = AVPlayer(URL: url)
player?.play()
}
else {
print("Oops, something wrong when playing video.mp4")
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
playVideo()
}
}