从 iOS 台设备播放视频文件
Play Video File from iOS Device
我在 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文件。
如何从我的设备播放视频而不是从项目中播放?
我可以从设备获取视频的路径和名称吗?
好的,根据您的情况,以下文档应该对您有所帮助 - 它是用 objective c 编写的,但您应该能够计算出 swift 对应的文件:
当你全部理解后,请标记为答案:)
我在 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文件。
如何从我的设备播放视频而不是从项目中播放?
我可以从设备获取视频的路径和名称吗?
好的,根据您的情况,以下文档应该对您有所帮助 - 它是用 objective c 编写的,但您应该能够计算出 swift 对应的文件:
当你全部理解后,请标记为答案:)