import UIKit
import MediaPlayer
class ViewController : UIViewController {
var moviePlayer: MPMoviePlayerController ?
override func viewDidLoad() {
super .viewDidLoad()
//定义一个视频文件路径
let filePath = NSBundle .mainBundle().pathForResource( "sample130" , ofType: "mp4" )
//定义一个视频播放器,通过本地文件路径初始化
moviePlayer = MPMoviePlayerController (contentURL: NSURL (fileURLWithPath: filePath!))
//设置播放器样式 - 全屏
moviePlayer!.controlStyle = MPMovieControlStyle . Fullscreen
//设置大小和位置
moviePlayer?.view.frame = self .view.frame
//添加到界面上
self .view.addSubview(moviePlayer!.view)
//开始播放
moviePlayer?.play()
}
override func didReceiveMemoryWarning() {
super .didReceiveMemoryWarning()
}
}
|