Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play video from NSData

I would like to know if it's possible to play a video from an NSData object... with the MPMoviePlayerController.

like image 509
Sergio Andreotti Avatar asked Feb 17 '11 08:02

Sergio Andreotti


1 Answers

Ben's answer works perfectly on simulator but wont work on the device, You cannot write anywhere on the device. Check code below

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.mp4"];

    [videoData writeToFile:path atomically:YES];
    NSURL *moveUrl = [NSURL fileURLWithPath:path];
    player = [[MPMoviePlayerController alloc]init];
    [player setContentURL:moveUrl];
    player.view.frame = viewPlayer.bounds;
    [viewPlayer addSubview:player.view];
    [player play];
like image 197
drexsien Avatar answered Oct 27 '22 06:10

drexsien