iphone - MPMoviePlayerController-切换 View 时黑屏

标签 iphone ios video mpmovieplayercontroller

背景图片是动画的天空

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

有人可以提出原因或解决方案吗?

谢谢!

亨利色彩视觉应用

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

最佳答案

尝试将观察者添加到播放器中。像这样:

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

}

关于iphone - MPMoviePlayerController-切换 View 时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14931949/

相关文章:

iOS 9.2 常规设置中缺少配置文件部分

iphone - 如何在uilabel中设置有限的字符数

iphone - 当 deviceOrientation 改变时重新加载 UITableView 中的数据

iPhone TableView 滚动时失去用户选择

ios UITextField 扩展(子类)

android - 关于如何在 android 中流式传输 m3u8 视频的任何想法

ios - 服务器收不到iOS发送的数据

ios - 如果使用 ScrollView ,内容 View 宽度不占用主视图宽度

ios - 如何在 Swift 中从本地视频 url 获取预览图像

loops - YouTube视频未循环播放