I'm having an issue when I try to encode a video in base64 within iOS 7.
I am not sure if my NSdata is being set correctly.
The video is playing on my iOS simulator, it's fine though. However when the code reaches the NSData block it is doing nothing and my logs for data and base64String are returning null.
Please check my code out
//Try to encode Video //Path of the video NSString *url = [[NSBundle mainBundle] pathForResource:@"trailer_iphone" ofType:@"m4v"]; //startthe player player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishCallBack) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; //set the frame player.view.frame = CGRectMake(10,10,300,300); [self.view addSubview:player.view]; //start to play [player play]; NSData *data = [[NSData dataWithContentsOfFile:@"trailer_iphone.m4v" ]base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength]; NSString *base64String = [data base64EncodedStringWithOptions:2]; NSLog(@"data = %@ base64String = %@",data, base64String);
Many Thanks!
I figure it out!!!!! In the NSData I cannot assign the a content as a File straightaway. First the video path must be declared, like a video player. For Example:
Than we declare the NSData referencing the previous path like this:
To finalize we just need to set the iOS7 base64 encode support:
That's it!!! Totally encoded!!!
If you wish to break your code in small chunks just see this link!
My final method is this one: