首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的MoviePlayer对函数没有响应

我的MoviePlayer对函数没有响应
EN

Stack Overflow用户
提问于 2010-10-30 16:14:54
回答 2查看 326关注 0票数 0

我正面临着内存泄漏和其他MoviePlayer新初始化的问题,因为我的MoviePlayer没有响应函数,在这些函数中,我在完成按钮上释放播放器。

代码语言:javascript
复制
(void) playMovieAtURL
{

    MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
    mpViewController.view.backgroundColor = [UIColor blackColor];
    [self presentMoviePlayerViewControllerAnimated:mpViewController];

    [mpViewController.view setCenter:self.view.center];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(myMovieFinishedCallback:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:mpViewController]; 

} 


    // When the movie is done,release the controller. (Doesn't come in it.)
-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{
    MPMoviePlayerController* theMovie=[aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:MPMoviePlayerPlaybackDidFinishNotification 
                                                  object:theMovie]; 

    // Release the movie instance created in playMovieAtURL
    [theMovie release]; 
}
EN

回答 2

Stack Overflow用户

发布于 2010-10-30 17:09:24

我不确定这是不是你的情况,但这是文档对MPMoviePlayerPlaybackDidFinishNotification的描述:

如果电影播放器在全屏模式下显示,并且用户点击了完成按钮,则不会发送此通知。在这种情况下,当播放器退出全屏模式时,完成按钮会导致影片播放暂停。如果要在代码中检测此场景,则应监视其他通知,如MPMoviePlayerDidExitFullscreenNotification。

似乎只有在电影停止时才会调用MPMoviePlayerPlaybackDidFinishNotification。如果您使用的是完成按钮,则应改用MPMoviePlayerDidExitFullscreenNotification。

票数 0
EN

Stack Overflow用户

发布于 2010-10-30 19:23:36

我试图通过传递nil来解决它,现在它返回给我回调,但电影仍然不会上映,我也会尝试你的建议。不管怎样,我的新代码

代码语言:javascript
复制
-(void) playMovieAtURL
{

MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
mpViewController.view.backgroundColor = [UIColor blackColor];
[self presentMoviePlayerViewControllerAnimated:mpViewController];

[mpViewController.view setCenter:self.view.center];

[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(myMovieFinishedCallback:) 
     name:MPMoviePlayerPlaybackDidFinishNotification 
 object:nil]; 

} 

// When the movie is done,release the controller. 
-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{
    MPMoviePlayerController* theMovie=[aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
        name:MPMoviePlayerPlaybackDidFinishNotification 
        object:nil]; 

    // Release the movie instance created in playMovieAtURL
    [theMovie release]; 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4057864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档