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 に答える