问题

NSData *data = [NSData dataWithContentsOfFile:@"vvideo.mp4" options:nil error:nil];
But as I log data, it returns null.
What is right way to convert any video to NSData?
File is added and copies properly in Xcode, you can see here.
EDITED QUESTION....
回答1:
dataWithContentsOfFile:options:error:
takes a file path and not file name. If the video file is in application bundle you should do,
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"vvideo" ofType:@"mp4"];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:filePath options:nil error:&error];
if(data == nil && error!=nil) {
//Print error description
}
Rather than passing error
argument as nil
pass the value, it will be useful in understanding error condition, if any occurs.
Hope that helps!
来源:https://stackoverflow.com/questions/19565373/how-to-convert-mp4-to-nsdata