【发布时间】:2012-03-09 11:20:08
【问题描述】:
我想预加载我的 MPMoviePlayerController,问题是 MPMoviePlayerController 花费了太多时间来准备,因此显示加载图标然后显示视频,如果我在直接播放后播放另一个视频但不是第一个时间... :(
我知道有这个:MPMoviePlayerLoadStateDidChangeNotification 但我不知道它实际上是如何工作的。
这是我的代码:
- (void) startSlideShow:(NSString *)nameFile
{
NSURL *url = [NSURL fileURLWithPath:nameFile];
MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.view.frame = CGRectMake(0, 0, 768, 1024);
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.view addSubview:moviePlayer.view];
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionFade];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.view layer] addAnimation:animation forKey:@"SwitchToView1"];
[moviePlayer setFullscreen:YES animated:YES];
}
-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
}
[self checkResources];
}
【问题讨论】:
标签: objective-c ipad mpmovieplayercontroller mpmovieplayer