play video in background swift 3
<p>hello im trying to play video in background but its give an error and the error is " unexpectedly found nil while unwrapping an Optional value " and im already set the video in Bundle and select copy if need </p>

<p>this the my code </p>

<pre><code>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)

    }
</code></pre>

<p>please any body have ideas for that , thank you </p>