你好我試圖在後臺播放視頻,但它給出了一個錯誤和錯誤是「意外地發現零,同時展開一個可選值」,我已經設置在視頻捆綁和選擇複製,如果需要在後臺播放視頻swift 3
這個我的代碼
import UIKit
import AVFoundation
class ViewController: UIViewController {
var avPlayer: AVPlayer!
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
let url = Bundle.main.url(forResource: "Grad_Cap_Toss", withExtension: "mp4")
avPlayer = AVPlayer(url: url!)
avPlayerLayer = AVPlayerLayer(player: avPlayer)
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
avPlayer.volume = 0
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEnd.none
avPlayerLayer.frame = view.layer.bounds
view.backgroundColor = UIColor.clear;
view.layer.insertSublayer(avPlayerLayer, at: 0)
NotificationCenter.default.addObserver(self,selector: Selector(("playerItemDidReachEnd:")),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,object: avPlayer.currentItem)
}
請任何機構擁有該出主意,謝謝
在'AVPlayer(url:url!)''url' nil? –
沒有它不是n! –
然後,你在哪條線上墜毀? –