次のViewController.mで新しいプロジェクトを作成しました。アプリを実行すると、予想される原点/サイズ (38、100、250、163) のボックスが表示されますが、黒く、ビデオが再生されません。Xcode に奇妙な出力があります。
2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay
2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
ビデオは Videora iPhone Converter で変換され、Xcode で正常に再生されることに注意してください (したがって、ビデオの問題ではありません)。demo-iPhone1 (存在しない) を指定すると nil 例外が発生するため、ビデオへのパスは問題ありません。私はシミュレーターとiPhoneで試しました:常にブラックボックス。何か案は?
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(38,
100,
250,
163)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end