本文介绍了MPMoviePlayerController无法在iOS4中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
的第一个答案
试图获得 MPMoviePlayerController
来玩。在模拟器(iOS4的iPhone设备)中,我听到声音但没有视频。在设备(iPhone 3GS和iOS4)上,我什么都没得到。这是我的代码:
to try and get MPMoviePlayerController
to play. In the simulator (iPhone device with iOS4), I hear sound but no video. On the device (iPhone 3GS and iOS4), I don't get anything. Here's my code:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
if ([moviePlayer respondsToSelector:@selector(view)]) {
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayer.view];
}
[moviePlayer play];
我有什么想法我做错了吗?
Any ideas what I'm doing wrong?
推荐答案
我刚刚在iOS4 + iPhone 4(和3GS)上测试了以下代码 - 工作正常。乍一看,我认为你的代码问题不是在 MPMoviePlayerController上调用
实例。 setFullscreen:animated
I just tested the following code on iOS4 + iPhone 4 (and a 3GS)—it works fine. At first blush, I think your code's problem is not calling setFullscreen:animated
on your MPMoviePlayerController
instance.
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(@"willEnterFullscreen");
}
- (void)enteredFullscreen:(NSNotification*)notification {
NSLog(@"enteredFullscreen");
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(@"willExitFullscreen");
}
- (void)exitedFullscreen:(NSNotification*)notification {
NSLog(@"exitedFullscreen");
[self.movieController.view removeFromSuperview];
self.movieController = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)playbackFinished:(NSNotification*)notification {
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
NSLog(@"playbackFinished. Reason: Playback Ended");
break;
case MPMovieFinishReasonPlaybackError:
NSLog(@"playbackFinished. Reason: Playback Error");
break;
case MPMovieFinishReasonUserExited:
NSLog(@"playbackFinished. Reason: User Exited");
break;
default:
break;
}
[self.movieController setFullscreen:NO animated:YES];
}
- (void)showMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteredFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSURL* movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tron" ofType:@"mov"]];
self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if ([self.movieController respondsToSelector:@selector(view)]) {
self.movieController.view.frame = self.view.frame;
[self.view addSubview:movieController.view];
[self.movieController setFullscreen:YES animated:YES];
}
[self.movieController play];
}
// This method is set as the action for an on-screen button
- (void)movieTime:(id)sender {
[self showMovie];
}
这篇关于MPMoviePlayerController无法在iOS4中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!