背景图片是动画天空
在设置页面(静态图像)和主页(动画图像)之间切换时,屏幕动画经常会掉落并变成单个黑色图像
有人可以提出理由或解决方案吗?
谢谢!
Henry Color Vision Apps
- (void)viewDidLoad
{
[super viewDidLoad];
self.mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iPhone4" ofType:@"mov"]]];
mp.repeatMode = MPMovieRepeatModeOne;
[mp.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
mp.scalingMode = MPMovieScalingModeFill;
[mp setFullscreen:YES];
mp.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:mp.view];
[self.view sendSubviewToBack:mp.view];
[mp prepareToPlay];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mp play];
}
答案 0 :(得分:0)
尝试向玩家添加观察者。像这样:
- (void)viewDidLoad
{
///...
self.mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iPhone4" ofType:@"mov"]]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mp];
///...
}
然后你可以得到错误:
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"Movie Finished.");
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackError) {
NSDictionary *notificationUserInfo = [notification userInfo];
NSError *mediaPlayerError = [notificationUserInfo objectForKey:@"error"];
if (mediaPlayerError)
{
NSLog(@"playback failed with error description: %@", [mediaPlayerError localizedDescription]);
}
else
{
NSLog(@"playback failed without any given reason");
}
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.mp];
}