MPMoviePlayerViewControllerを使用してiPhoneSDKでビデオを再生する方法。ここでは、デバイスを介してビデオをキャプチャし、その特定のビデオをドキュメントディレクトリに保存します。誰か教えてください…。
1 に答える
1
ドキュメントディレクトリパスを取得します。
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
次に、NSFileManagerの任意のディレクトリリストAPIを使用できます。
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
これで、すべてのコンテンツがディレクトリパス(すべてのビデオが保存されている)に配列されました。
NSURL *videoURL = [NSURL UrlWithString:[NSString stringWithFormat:@"%@/%@",documentsDirectory,[directoryContents objectAtIndex:0]]]; //check which url u want play as video name is in nsarray i have selected one random video name.
MovieControllerPlayerインスタンスを使用してURLを再生します。
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController.view setCenter:yourView.center];
//[mpViewController release];
お役に立てば幸いです。
于 2012-06-04T17:46:07.630 に答える