How to play video from NSData

前端 未结 4 1920
长情又很酷
长情又很酷 2020-12-15 09:38

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

4条回答
  •  借酒劲吻你
    2020-12-15 10:29

    It is better to use NSFileManager in this case instead writeToFile

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.mp4"];
    
    [[NSFileManager defaultManager] createFileAtPath:path contents:videoData attributes:nil];
    
    NSURL *moveUrl = [NSURL fileURLWithPath:path];
    player = [[MPMoviePlayerController alloc]init];
    [player setContentURL:moveUrl];
    player.view.frame = viewPlayer.bounds;
    [viewPlayer addSubview:player.view];
    [player play];
    

提交回复
热议问题