本文介绍了如何从NSData播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以使用MPMoviePlayerController从NSData对象播放视频.
I would like to know if it's possible to play a video from an NSData object... with the MPMoviePlayerController.
推荐答案
Ben的答案在模拟器上效果很好,但在设备上不起作用,您无法在设备上的任何位置写东西.检查下面的代码
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];
这篇关于如何从NSData播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!