我使用MPMoviePlayerController播放存储在ios6文档的子文件夹中的视频,但它不';行不通

我使用MPMoviePlayerController播放存储在ios6文档的子文件夹中的视频,但它不';行不通,ios,mpmovieplayercontroller,document-storage,Ios,Mpmovieplayercontroller,Document Storage,我使用MPMoviePlayerController播放存储在ios6文档中名为test1的子文件夹中的视频,但它不起作用 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [paths objectAtIndex:0];// NSString *movieFolderPath = [docu

我使用
MPMoviePlayerController
播放存储在ios6文档中名为test1的子文件夹中的视频,但它不起作用

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];//
NSString *movieFolderPath = [documentDirectory stringByAppendingPathComponent:@"/test1"];
NSString *newsrc = [[NSString alloc]initWithFormat:@"/%@",new.src ];
NSString *moviePath   = [movieFolderPath stringByAppendingPathComponent:newsrc];
NSURL *url = [[NSURL alloc]initWithString: [moviePath  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] ];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
_moviePlayer.movieSourceType = MPMovieSourceTypeFile;
_moviePlayer.view.frame = new.region;
[_moviePlayer prepareToPlay];
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
嗯:url是/Users/fengsu/Library/Application Support/iPhone Simulator/6.0/Applications/53C97346-C8FD-42DF-AD37-F2B14D5D3984/Documents/test1/v1.mp4


我认为url有问题,但我不知道为什么,请帮助我,非常感谢

问题是如何构造
NSURL
对象

MPMoviePlayerController
要求指向本地文件的URL具有
file://
前缀

方法如下:

NSString *filename = @"your_video.mpeg";
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [pathArray objectAtIndex:0];
NSString *yourVideoPath = [documentsDirectory stringByAppendingPathComponent:filename];
NSURL *movieURL = [NSURL fileURLWithPath:yourVideoPath isDirectory:NO];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
// Rest of the code...

使用
[NSURL fileURLWithPath:moviePath]

用于从文件中打开URL。

非常感谢您的帮助。这个方法解决了我的问题。