1

当应用程序开始时,视频将自动运行

但是按下主页按钮并再次打开应用程序冻结并且不知道为什么

我能做些什么?

- (void)viewDidLoad{

    m_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
            [m_player.backgroundView setBackgroundColor:[UIColor blackColor]];
            [m_player.view setBackgroundColor:[UIColor blackColor]];
            [m_player setControlStyle:MPMovieControlStyleNone];
            [[m_player view] setFrame:[self.view bounds]];

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

            [m_player play];
            [self.view addSubview:[m_player view]];
    }


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

        [[NSNotificationCenter defaultCenter] removeObserver:self
                                              name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:nil];

        [m_player.view removeFromSuperview];
        [m_player stop];
        m_player = nil;

    }

}
4

1 回答 1

2

这段代码帮助我避免在按下主页按钮并且视频播放和工作时冻结应用程序!!!

[[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(handleEnteredBackground:)
                                             name: UIApplicationDidEnterBackgroundNotification
                                           object: nil];




-(void)handleEnteredBackground:(NSNotification*)_notification{

   [m_player play];

}
于 2012-11-15T16:21:18.317 回答