Swift2 Swift 2-fileURLWithPath返回零

Swift2 Swift 2-fileURLWithPath返回零,swift2,mpmovieplayercontroller,mp4,Swift2,Mpmovieplayercontroller,Mp4,我正在尝试使用MPMoviePlayerController加载视频。我已经在我的项目中添加了该文件,还将其添加到构建阶段“复制捆绑资源” 当我调用函数打开视频时,我可以看到路径已经打印出来,但是应用程序在“fileURLWithPath”上崩溃 我做错了什么?.mp4苍蝇可玩吗 func firstView(){ if let filePath = NSBundle.mainBundle().pathForResource("firstVideo", ofType: "m

我正在尝试使用
MPMoviePlayerController
加载视频。我已经在我的项目中添加了该文件,还将其添加到构建阶段“复制捆绑资源”

当我调用函数打开视频时,我可以看到路径已经打印出来,但是应用程序在“fileURLWithPath”上崩溃

我做错了什么?
.mp4
苍蝇可玩吗

 func firstView(){

        if let filePath  = NSBundle.mainBundle().pathForResource("firstVideo", ofType: "mp4") {

            print(filePath)
//PRINTS: /var/mobile/Containers/Bundle/Application/B93BB049-DA87-4D89-AEBE-A5C92C01726E/MyApp.app/firstVideo.mp4

            firstMoviePlayer!.contentURL = NSURL.fileURLWithPath(filePath) // fatal error
        }


        firstMoviePlayer!.repeatMode = .None
        firstMoviePlayer!.controlStyle = MPMovieControlStyle.Embedded

        firstMoviePlayer!.view.frame = FirstTimeVideoView.frame
        FirstTimeVideoView.addSubview(firstMoviePlayer!.view)

        firstMoviePlayer!.play()


    }

您只需更改:

if let filePath  = NSBundle.mainBundle().pathForResource("firstVideo", ofType: "mp4") {

            print(filePath)
//PRINTS: /var/mobile/Containers/Bundle/Application/B93BB049-DA87-4D89-AEBE-A5C92C01726E/MyApp.app/firstVideo.mp4

            firstMoviePlayer!.contentURL = NSURL.fileURLWithPath(filePath) // fatal error
        }
致:


谢谢,但我得到错误:无法转换NSURL?要打印:file:///var/mobile/Containers/Bundle/Application/5B983567-AD2B-417A-B384-4218562E3796/myApp.app/firstVideo.mp4 但再次返回致命错误
if let filePath  = NSBundle.mainBundle().URLForResource("firstVideo", ofType: "mp4") {

            print(filePath)
//PRINTS: /var/mobile/Containers/Bundle/Application/B93BB049-DA87-4D89-AEBE-A5C92C01726E/MyApp.app/firstVideo.mp4

            firstMoviePlayer!.contentURL = NSURL.fileURLWithPath(filePath) // fatal error
        }