2

背景图像是动画天空

在设置页面(静态图像)和主页(动画图像)之间切换时,屏幕动画经常掉线并变成单个黑色图像

任何人都可以提出原因或解决方案吗?

谢谢!

亨利色觉应用

- (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];
}
4

1 回答 1

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];

}

于 2013-07-20T14:05:50.523 回答