我的应用在应用启动时以全屏模式播放视频。从3.0到4.1,一切都完美无缺。
但是,如果我为通用应用程序编译相同的代码,它将在iPad上运行,但不再适用于iPhone(模拟器)。
有没有人解决过这个问题?
以下是代码:
if ([self respondsToSelector:@selector(presentMoviePlayerViewControllerAnimated:)]) {
videoPath = [[NSBundle mainBundle] pathForResource:@"portrait" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayerController = aMoviePlayerController;
[aMoviePlayerController release];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[moviePlayerController.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
} else {
//OS < 3.2
videoPath = [[NSBundle mainBundle] pathForResource:@"landscape" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayerController = aMoviePlayerController;
[aMoviePlayerController release];
moviePlayerController.movieControlMode = MPMovieControlModeHidden;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
}
这是错误:
- [MPMoviePlayerControllerOld view]:无法识别的选择器发送到实例
0x7924470
即使我试图阻止这样......
if ([moviePlayerController respondsToSelector:@selector(view)]) {
[moviePlayerController.view setFrame:self.view.bounds];
}
......仍然会抛出错误。
答案 0 :(得分:1)
我还没有解释错误。但这似乎有效(需要在旧设备上进行测试):
if ([self respondsToSelector:@selector(presentMoviePlayerViewControllerAnimated:)]) {
videoPath = [[NSBundle mainBundle] pathForResource:@"portrait" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:videoPath];
/* NEW */
MPMoviePlayerViewController *aMoviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
aMoviePlayerViewController.moviePlayer.view.frame = self.view.bounds;
aMoviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[aMoviePlayerViewController.moviePlayer play];
[self.view addSubview:aMoviePlayerViewController.view];
self.moviePlayerController = aMoviePlayerViewController;
} else {
//OS < 3.2
videoPath = [[NSBundle mainBundle] pathForResource:@"landscape" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayerController = aMoviePlayerController;
aMoviePlayerController.movieControlMode = MPMovieControlModeHidden;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
[aMoviePlayerController release];
}
如果我只记得为什么我在第一时间以另一种方式做到了;)
答案 1 :(得分:1)
我前几天得到了同样的错误。它只需要将基本sdk从3.2更改为4.1 希望它有所帮助