1

iPadでMPMoviePlayerControllerを使用してビデオをたくさん再生するアプリを書いています。問題は、約15時間前に動作を停止したときにアプリが正常に動作し、ビデオを再生していたのに、ビデオが再生されないことです。MPMoviePlayerControllerはビデオの最初のフレームを表示し、フルスクリーンビューではムービーをうまくスクラブできますが、再生を押すとすぐに一時停止します。以下のコードがあります。デバッグ時に、playを呼び出すと、playbackStateがMPMoviePlaybackStatePlayingであるMPMoviePlayerPlaybackStateDidChangeNotificationが送信され、すぐに、playbackStateがMPMoviePlaybackStatePausedである別のMPMoviePlayerPlaybackStateDidChangeNotification通知が送信されることに気付きました。それが役立つかどうかはわかりませんが、私のコードに何か問題がある場合やアイデアがある場合はお知らせください。

- (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];
        }
    }
}
4

1 に答える 1

1

私はそれを理解したと思います、私はプレイするすべての呼び出しの前に次のコードを置きました

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

誰か他の人が何か入力を持っているなら私に知らせてください

于 2010-06-29T08:36:09.433 に答える