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 に答える