从iOS设备播放视频文件

时间:2015-06-24 06:35:37

标签: ios swift cocoa-touch mpmovieplayercontroller

我在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文件保存在我的项目中。

如何从我的设备而不是从项目中播放视频?

我可以从设备获取视频的路径和名称吗?

1 个答案:

答案 0 :(得分:-2)