سؤال

أنا أكتب تطبيقًا سيعزف مقاطع الفيديو كثيرًا باستخدام mpmoviePlayerController على iPad. المشكلة هي أن التطبيق كان يعمل بشكل جيد ولعب مقاطع الفيديو عندما توقفت عن العمل منذ حوالي 15 ساعة ولكن الآن لا يتم تشغيل مقاطع الفيديو. سيعرض MpMoviePlayerController الإطار الأول من الفيديو ، وفي عرض ملء الشاشة ، يمكنني التنظيف عبر الفيلم بشكل جيد ، لكن عندما أضغط على تشغيله على الفور. لديّ الرمز أدناه ، عندما لاحظت تصحيح الأخطاء أنه عندما أسميه ، يرسل MpmoviePlayerPlayBackStatedIdChangenotification مع PlayBackState كونه mpmovieplaybackstateplaying ، ثم يرسل على الفور mpmovieplayerplaybackstatediDchangenotification مع pladbackstate mpmovieplaypaplaypaplaypapaplaypapaplaypapaplaypapaplaypapapling. لست متأكدًا مما إذا كان ذلك يساعد ولكن يرجى إعلامي إذا كنت ترى أي شيء خاطئ في الكود الخاص بي أو لديك أفكار ، شكرًا.

- (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];
        }
    }
}
هل كانت مفيدة؟

المحلول

أعتقد أنني اكتشفت ذلك ، وضعت الكود التالي قبل كل مكالمة للعب

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

يعمل الآن ، إذا كان لدى أي شخص آخر أي مدخلات ، فأخبرني بذلك

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top