MPMoviePlayerController 在点击“完成”时提供无限循环

发布于 2025-01-05 02:02:32 字数 3231 浏览 1 评论 0原文

我尝试让 MPMoviePlayerController 工作,但遇到了一个奇怪的问题。播放时,我单击“完成”按钮,似乎触发了无限的外观:

2012-02-13 15:18:04.395 iDomsPortalDev[7376:12203] 播放完毕。 原因:用户退出 2012-02-13 15:18:04.395 iDomsPortalDev[7376:12203] 播放完毕。原因:用户退出 2012-02-13 15:18:04.395 iDomsPortalDev[7376:12203]播放完成。原因:用户退出

我在启动时使用以下通知:

- (void) showMoviePlayer {
    [[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];      

    id appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];
    //[[self navigationController] presentMoviePlayerViewControllerAnimated:[appDelegate movieController]];    
    [[appDelegate moviePlayer].view setFrame: self.view.bounds];
    [self.view addSubview:[appDelegate moviePlayer].view];
    [[appDelegate moviePlayer] setFullscreen:YES animated:YES];    
}

以及以下侦听器:

#pragma mark - Movieplayer feedback
- (void)willEnterFullscreen:(NSNotification*)notification {
    NSLog(@"willEnterFullscreen");
}

- (void)enteredFullscreen:(NSNotification*)notification {
    NSLog(@"enteredFullscreen");
}

- (void)willExitFullscreen:(NSNotification*)notification {
    NSLog(@"willExitFullscreen");
}

- (void)exitedFullscreen:(NSNotification*)notification {
    NSLog(@"exitedFullscreen");
    iDomsAppDelegate *appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];    
    [[appDelegate moviePlayer].view removeFromSuperview];
    [[appDelegate moviePlayer] release];
    [appDelegate setMovieController:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)playbackFinished:(NSNotification*)notification {
    iDomsAppDelegate *appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];    
    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;
    }
    [[appDelegate moviePlayer] setFullscreen:NO animated:YES];
}

仅调用 PlayBackFinished 选择器(无限次),因此我一定做了一些愚蠢的事情(在 iOS5 的模拟器中运行)

I try to get a MPMoviePlayerController to work, but have a strange problem. When playing I click the done button and there seems an infinite look triggered:

2012-02-13 15:18:04.395 iDomsPortalDev[7376:12203] playbackFinished.
Reason: User Exited 2012-02-13 15:18:04.395 iDomsPortalDev[7376:12203]
playbackFinished. Reason: User Exited 2012-02-13 15:18:04.395
iDomsPortalDev[7376:12203] playbackFinished. Reason: User Exited

I use the following notifications on starting:

- (void) showMoviePlayer {
    [[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];      

    id appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];
    //[[self navigationController] presentMoviePlayerViewControllerAnimated:[appDelegate movieController]];    
    [[appDelegate moviePlayer].view setFrame: self.view.bounds];
    [self.view addSubview:[appDelegate moviePlayer].view];
    [[appDelegate moviePlayer] setFullscreen:YES animated:YES];    
}

and the following listeners:

#pragma mark - Movieplayer feedback
- (void)willEnterFullscreen:(NSNotification*)notification {
    NSLog(@"willEnterFullscreen");
}

- (void)enteredFullscreen:(NSNotification*)notification {
    NSLog(@"enteredFullscreen");
}

- (void)willExitFullscreen:(NSNotification*)notification {
    NSLog(@"willExitFullscreen");
}

- (void)exitedFullscreen:(NSNotification*)notification {
    NSLog(@"exitedFullscreen");
    iDomsAppDelegate *appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];    
    [[appDelegate moviePlayer].view removeFromSuperview];
    [[appDelegate moviePlayer] release];
    [appDelegate setMovieController:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)playbackFinished:(NSNotification*)notification {
    iDomsAppDelegate *appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];    
    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;
    }
    [[appDelegate moviePlayer] setFullscreen:NO animated:YES];
}

Only the PlayBackFinished selector is called (infinite times), so there must be something stupid I do (running in the simulator with iOS5)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2025-01-12 02:02:32

我发现了问题,似乎是设置了全屏选项导致的:

[[appDelegate moviePlayer] setFullscreen:YES animated:YES];

I found the problem, it seemed to have been setting the fullscreen option which caused it:

[[appDelegate moviePlayer] setFullscreen:YES animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文