5

我正在尝试让我的应用播放已下载到文档目录的视频文件。我知道文件正在下载,但我似乎无法播放文件,这是我的代码:

-(IBAction)play{

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

NSURL *movieURL = [NSURL fileURLWithPath:path];


_player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:_player.view];

_player.controlStyle = MPMovieControlStyleDefault;
_player.shouldAutoplay = YES;


[_player setFullscreen:YES animated:YES];


[_player play];

}
4

2 回答 2

12

这看起来像是某种错误,但您必须像这样设置路径:

 NSString *vidPath = [[NSBundle mainBundle] pathForResource:@"promo" ofType:@"mp4"];
 NSURL *url = [NSURL fileURLWithPath:vidPath isDirectory:NO]; //THIS IS THE KEY TO GET THIS RUN :) 
 [introPlayer setContentURL:url];
于 2012-09-24T13:25:36.877 回答
0

问题将出在这一行:NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"];

将其更改为NSString *path = [documentsDirectory stringByAppendingPathComponent:@"piggy.m4v"];

于 2012-07-18T19:54:10.040 回答