How to convert mp4 to NSData?

enter image description here I have a file in Xcode named vvideo.mp4. I am trying to convert it to NSData as shown below.

NSData *data = [NSData dataWithContentsOfFile:@"vvideo.mp4" options:nil error:nil]; 

But when I register the data, it returns null.

What is the correct way to convert any video to NSData?

The file is added and copied correctly in Xcode, you can see here.

UNITED QUESTION ....

0
source share
1 answer

dataWithContentsOfFile:options:error: accepts the file path, not the file name. If the video file is in the application bundle, you must 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 } 

Instead of passing the error argument as nil to pass the value, it will be useful in understanding the error condition if that happens.

Hope this helps!

+7
source

All Articles