【发布时间】:2015-06-24 06:35:36
【问题描述】:
我在我的 iOS 应用程序上播放视频。
func playVideo() {
if let path = NSBundle.mainBundle().pathForResource("video", ofType:"mp4"),
url = NSURL(fileURLWithPath: path),
moviePlayer = MPMoviePlayerController(contentURL: url) {
self.moviePlayer = moviePlayer
moviePlayer.view.frame = self.view.bounds
moviePlayer.prepareToPlay()
moviePlayer.controlStyle = MPMovieControlStyle.None
moviePlayer.view.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height)
moviePlayer.scalingMode = .AspectFill
self.view.addSubview(moviePlayer.view)
if (oldMoviePlayer != nil){
println("Animation Run")
UIView.transitionFromView(oldMoviePlayer!.view, toView: moviePlayer.view, duration: 1.0, options: transitionOptions, completion: nil)
}
oldMoviePlayer = moviePlayer
} else {
debugPrintln("Ops, something wrong when playing video.m4v")
}
}
现在 video.mp4 文件保存在我的项目中。
如何从我的设备而不是项目中播放视频?
我可以从设备获取视频的路径和名称吗?
【问题讨论】:
标签: ios swift cocoa-touch mpmovieplayercontroller