0

我有一个按顺序显示图像和/或电影的应用程序。问题是,我不能关闭一个电影播放器​​,然后再展示另一个。如果我尝试,我会收到消息“警告:在演示过程中尝试在 MyViewController 上演示 MPMoviePlayerViewController!” 与其他动画呈现/解除方法不同,没有完成处理程序,也没有呈现/解除的非动画版本。

这是我的代码的简化版本:

-(void) play
{
    [[window rootViewController] presentMoviePlayerViewControllerAnimated:player];
    [[_player moviePlayer] play];
}

-(void) videoNotification:(NSNotification *) notification
{
    if([notification.name isEqualToString:MPMoviePlayerPlaybackDidFinishNotification])
    {
        [[window rootViewController] dismissMoviePlayerViewControllerAnimated];
        [_canvasManager showNextCanvas]; //this calls play on the next canvas
    }
}

关于如何实现我的目标的任何想法/提示?

4

1 回答 1

0

在查看了dismissViewControllerAnimated:completion:之后,我能够通过创建 MPMoviePlayerViewController 的子类并覆盖 -(void)viewDidDisappear 来创建完成处理程序。viewDidDisappear 在dismissMoviePlayerViewControllerAnimated 结束时被调用。

@interface MyMoviePlayerViewController : MPMoviePlayerViewController
{
    void (^_viewDidDisappearCallback)(void);
}

- (void)setViewDidDisappearCallback:(void (^)(void))callback;

@end    

@implementation MyMoviePlayerViewController

- (id) initWithContentURL:videoPath
{
    self = [super initWithContentURL:videoPath];
    _viewDidDisappearCallback = nil;    
    return self;
}

- (void)setViewDidDisappearCallback:(void (^)(void))callback
{
    _viewDidDisappearCallback = [callback copy];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];    
    if(_viewDidDisappearCallback != nil)
        _viewDidDisappearCallback();
}

@end
于 2014-07-03T00:20:24.867 回答