此篇文播放影片之範例程式, 在storyBoard須先行設定一Button

並與AVPlayerViewController建立關聯性, 並選擇Kind為Present Modaily

程式碼如下:

import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
    {
        let destination = segue.destinationViewController as! AVPlayerViewController
        
        destination.player = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("P1090296", ofType: "MOV")!))
    }
}

    全站熱搜

    Will 發表在 痞客邦 留言(0) 人氣()