Nsurl from String Gets Truncated, Dots on the Uivideoeditorcontroller's Video Path Swift 2 iOS 8

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

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

NSURL(fileURLWithPath: editedVideoPath)

instead of

NSURL(string: editedVideoPath)

swift auto-abbreviates my NSURL with ... over the characters it can't fit?

For above problem instead of the locationURL = NSURL(string: filePath) you can use the locationURL = NSURL(fileURLWithPath: filePath)

   let filePath = "/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data/Application/CE6698CD-98D4-4DEA-8C01-CE70029D922B/Documents/looks/2052f438-5a75-11e6-914c-06bcb4e621d1.mp4"
let locationURL = NSURL(fileURLWithPath: filePath)
print("the url = \(locationURL)")

How to convert video data to NSURL

First Save your Video data to a file then try to access that as a file URL.
Here is an example.

 NSString *filePath = [self documentsPathForFileName:@"video.mp4"];
NSData *videoAsData; // your data here
[videoAsData writeToFile:filePath atomically:YES];

// access video as URL
NSURL *videoFileURL = [NSURL fileURLWithPath:filePath];

- (NSString *)documentsPathForFileName:(NSString *)name
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

return [documentsPath stringByAppendingPathComponent:name];
}

For Swift 3.0:

let filePath = self.documentsPathForFileName("video.mp4")
let videoAsData = NSData()
videoAsData.write(toFile: filePath, atomically: true)
let videoFileURL = NSURL(fileURLWithPath: filePath)

func documentsPathForFileName(name: String) -> String {
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
return documentsPath.appending(name)
}

Comparing empty NSURL

If your NSLog prints "Image URL:" that doesn't indicate that your NSURL is nil or null; it indicates that your NSURL's string is empty. If your NSURL was null but still executing that second conditional, your NSLog would print: "Image URL: (null)" instead.

To check whether your NSURL's string is empty (since it seems as if you're storing NSURL's in all indexes of your array, but simply storing an NSURL with an empty string at the "empty" indices), change your conditional to the following:

if(myImageUrls.absoluteString.length == 0){
NSLog(@"URL empty %@", myImageUrls);
}
else{
//NSURL *url = imageUrls;
NSLog(@"Image URL:%@", myImageUrls);
}

Swift doesn't return the localized version for URLResourceKey.localizedNameKey

The code is fine.

I'll bet you have a separate Swift project, and just forgot to set CFBundleLocalizations in Info.plist:

<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>it</string>
</array>

Anything not in this array won't work properly.

Re-render video using the new Photos Framework in iOS8

fullSizeImageURL is for working with Photo assets. You want the avAsset property when working with a video. Modify the actual video, not the metadata, by writing a new video file.

To do that, you could use that avAsset in an AVMutableComposition:

Insert the appropriate time range of the avAsset's video track (AVAssetTrack) into an AVMutableCompositionTrack. That'll do your trimming.

Place/size it appropriately using layer instructions. (AVMutableVideoCompositionLayerInstruction) to do your cropping and scaling.



Related Topics



Leave a reply



Submit