【问题标题】:When my movie is finished to play, the app crashes当我的电影播放完毕后,应用程序崩溃了
【发布时间】:2023-03-13 16:15:01
【问题描述】:

我尝试通过单击按钮来启动电影。当我点击电影播放器​​出现并且工作正常。电影播放到最后,电影播放器​​消失。消失后,我的应用崩溃了……

我在标签栏应用程序中使用我的视图控制器和这段代码:

- (void)moviePlayBackDidFinish:(NSNotification *) aNotification{

    MPMoviePlayerController *player = [aNotification object];
    [player setFullscreen:NO animated:YES];
    [player.view removeFromSuperview];
    [player stop];
    player.initialPlaybackTime = -1.0;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [player release];
    player=nil;
}

- (IBAction)playVideo:(UIButton *)playButton{
    NSString *url = [[NSBundle mainBundle] pathForResource:@"Teaser 04" ofType:@"mov"];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    player.shouldAutoplay = YES;
    player.view.frame = CGRectMake(0., 44., self.view.bounds.size.width, self.view.bounds.size.height-44);
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [self.view addSubview:player.view];
    [player play];
}

我不知道我做错了什么。我只想配置一个启动视频的按钮,当视频结束时,MoviePlayer 视图消失,应用程序回到我的初始 .xib

感谢您的帮助

【问题讨论】:

    标签: objective-c ipad mpmovieplayercontroller


    【解决方案1】:

    我找到了解决方案,我不知道它是否是最好的,但我希望它可以工作:

    - (void)movieFinishedCallBack:(NSNotification *) aNotification{
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [player.view removeFromSuperview];
    [player stop];
    [player release];
    

    }

    - (IBAction)playVideo:(UIButton *)playButton{
    NSString *url = [[NSBundle mainBundle] pathForResource:@"Teaser 04" ofType:@"mov"];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    player.view.frame = CGRectMake(0, 0, 950, 600);
    [self.view addSubview:player.view];
    [player play];
    

    }

    【讨论】:

      【解决方案2】:

      我可能是错的,但我的猜测是播放器在回溯中的某处被用于调用 moviePlayBackDidFinish: ... - 是个坏消息,因为堆栈中的某处仍需要该对象。

      查看这篇文章了解更多详情:How to release MPMoviePlayerController?

      【讨论】:

      • 感谢您的链接,但不是这个。我通过movieFinishedCallBack切换功能moviePlayBackDidFinish
      • 他不是释放播放器而是释放它。
      • 他不是通过在那里调用“释放”来有效地释放它吗?
      猜你喜欢
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多