Question

J'écris une application qui sera diffuse des vidéos en utilisant beaucoup le MPMoviePlayerController sur l'iPad. Le problème est l'application fonctionnait très bien et jouer les vidéos quand je travaille il y a environ arrêtai 15 heures, mais maintenant les vidéos ne fonctionnent pas. Le MPMoviePlayerController affichera la première image de la vidéo et en mode plein écran, je peux frotter à travers le beau film, mais quand je frappe jouer juste fait une pause tout de suite. J'ai le code ci-dessous, lors du débogage j'ai remarqué que quand je l'appelle jouer envoie un MPMoviePlayerPlaybackStateDidChangeNotification avec le playbackState étant MPMoviePlaybackStatePlaying puis tout de suite, il envoie une notification MPMoviePlayerPlaybackStateDidChangeNotification avec playbackState étant MPMoviePlaybackStatePaused. Je ne sais pas si cela aide, mais s'il vous plaît laissez-moi savoir si vous voyez quelque chose de mal dans mon code ou avoir une idées, merci.

- (void)handleNotification:(NSNotification *)notification {
    if ([[notification name] isEqualToString:MPMoviePlayerPlaybackStateDidChangeNotification]) {
        if (_videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
            _playButtonLarge.hidden = YES;
            _scrubber.maximumValue = _videoPlayer.duration;
            [_playPauseButton setBackgroundImage:[UIImage imageNamed:@"video_controls_pause.png"] forState:UIControlStateNormal];
            if (_updateScrubberTimer == nil) {
                _updateScrubberTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateScrubber) userInfo:nil repeats:YES];
            }
        } else if (_videoPlayer.playbackState == MPMoviePlaybackStatePaused || _videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
            [_playPauseButton setBackgroundImage:[UIImage imageNamed:@"video_controls_play.png"] forState:UIControlStateNormal];
            _playButtonLarge.hidden = NO;
            if (_updateScrubberTimer != nil) {
                [_updateScrubberTimer invalidate];
                _updateScrubberTimer = nil;
            }
            if (_videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
                _scrubber.value = 0.0f;
                _timePlayedLabel.text = @"0:00";
                _timeRemainingLabel.text = @"-0:00";
                _videoPlayerBG.hidden = NO;
            }
        }
    } else if ([[notification name] isEqualToString:MPMoviePlayerPlaybackDidFinishNotification]) {
        NSNumber *reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
        if ([reason intValue] == MPMovieFinishReasonPlaybackEnded) {
            _videoPlayerBG.hidden = NO;
        }
        _scrubber.value = _scrubber.maximumValue;
    }
}

- (void)playPause {
    if ([_videos count] > 0) {
        if (_videoPlayer.playbackState == MPMoviePlaybackStatePaused || _videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
            _playButtonLarge.hidden = YES;
            _videoPlayerBG.hidden = YES;
            if ([_videoPlayer contentURL] == nil) {
                Video *video = [_videos objectAtIndex:0];
                [_videoPlayer setContentURL:video.videoURL];
            }
            if (![_videoPlayer isPreparedToPlay]) {
                [_videoPlayer prepareToPlay];
            }
            [_videoPlayer play];
        } else if (_videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
            _playButtonLarge.hidden = NO;
            [_videoPlayer pause];
        }
    }
}
Était-ce utile?

La solution

Je pense que j'ai tout compris, je mets le code suivant avant chaque appel à jouer

if (![_videoPlayer isPreparedToPlay]) { [_videoPlayer prepareToPlay]; }

fonctionne maintenant, si quelqu'un d'autre une entrée me faire savoir

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top