NSURL from String gets truncated, dots on the UIVideoEditorController's video path Swift 2 iOS 8

隐身守侯 提交于 2019-12-02 14:10:12

问题


I can't get the full NSURL of the editedVideoPath, here's my code:

// GLOBAL VARIABLES
    var videoPath = String()
    var videoURL = NSURL()


// Video Editor delegate
func videoEditorController(editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
        if saveToPhotoLibrary {
            if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(editedVideoPath) {
                UISaveVideoAtPathToSavedPhotosAlbum(editedVideoPath, self, nil, nil)
            }
            print("SAVED TO PHOTO LIBRARY AT: \(editedVideoPath)")
         }

        videoPath = editedVideoPath
        videoURL = NSURL(string: editedVideoPath)!
        print("VIDEO PATH: \(videoPath)")
        print("VIDEO URL: \(videoURL)")
        dismissViewControllerAnimated(true, completion: nil)
    }

The problem is the I can't get the full NSURL out of the videoPath string, here's what the XCode console prints out:

VIDEO PATH: /private/var/mobile/Containers/Data/Application/D7536AD4-353A-48CA-8F31-2D78F9F10730/tmp/trim.BFF7D20F-138A-46A2-A58E-76736AF7343E.MOV
VIDEO URL: /private/var/mobile/Containers/Data/Application/D7536AD4-353A-48CA-8F31-2D78F9F10730/tmp/trim.BFF7D20F-138A-46A2-A58E-76 ... 343E.MOV

As you can see, the VIDEO URL gets dots almost by the end of it, while the VideoPath string is correct. This is a pretty wired issue I've never encountered before with this NSURL statement:

    videoURL = NSURL(string: editedVideoPath)!

Since I need to upload that edited video to a web server, I need its full correct url. I thought is was a print() issue, but if I try to grab the videoURL XCode tells me that it's nil, so print() function tells the truth :(

I've searched here and there on stackoverflow, no success.

Hope someone can help, Thanks!


回答1:


Since you're using a file path, you want to use

NSURL(fileURLWithPath: editedVideoPath)

instead of

NSURL(string: editedVideoPath)


来源:https://stackoverflow.com/questions/34090094/nsurl-from-string-gets-truncated-dots-on-the-uivideoeditorcontrollers-video-pa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!