【问题标题】:MPMoviePlayerController play error on iPadiPad 上的 MPMoviePlayerController 播放错误
【发布时间】:2010-06-29 01:33:11
【问题描述】:

我正在编写一个应用程序,它将使用 iPad 上的 MPMoviePlayerController 大量播放视频。问题是当我大约 15 小时前停止工作时,该应用程序运行良好并播放视频,但现在视频无法播放。 MPMoviePlayerController 将显示视频的第一帧,在全屏视图中我可以很好地浏览电影,但是当我点击播放时它会立即暂停。我有下面的代码,在调试时我注意到当我调用 play 时,它会发送一个 MPMoviePlayerPlaybackStateDidChangeNotification,playbackState 为 MPMoviePlaybackStatePlaying,然后它立即发送另一个 MPMoviePlayerPlaybackStateDidChangeNotification 通知,playbackState 为 MPMoviePlaybackStatePaused。不确定这是否有帮助,但如果您在我的代码中发现任何错误或有任何想法,请告诉我,谢谢。

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

【问题讨论】:

    标签: iphone iphone-sdk-3.0 ipad mpmovieplayercontroller mpmovieplayer


    【解决方案1】:

    我想我想通了,我在每次调用播放之前都放了以下代码

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

    现在可以了,如果有其他人有任何意见,请告诉我

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      相关资源
      最近更新 更多