Objective-c,AVPlayer花费太多时间从URL恢复播放音频

时间:2015-09-01 17:34:19

标签: ios objective-c iphone audio avplayer

我已经实施了AVPlayer。它工作正常。但是,在从URL播放音频期间,它会多次自动停止/暂停,并且需要很长时间才能恢复/重放。另一方面,如果我手动暂停和播放它工作正常意味着它不需要太多时间重新播放。我想在它准备好的时候恢复/重播它。任何建议都会很棒。预先感谢 !!!!!!!! 我的代码:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if (!songFinished) {
if (object == playerItem && [keyPath isEqualToString:@"playbackBufferEmpty"])
{
    if (playerItem.playbackBufferEmpty) {            

        printf("\n\n\t****player item playback buffer is empty****\n\n");

        //[s activityIndicator] startAnimating];
        [player pause];
    }
}
else if (object == playerItem && [keyPath isEqualToString:@"playbackLikelyToKeepUp"])
{
    if (playerItem.playbackLikelyToKeepUp)
    {
        printf("\n\n\t****Ready to Play audio ****\n\n");

        [player play];

        //Your code here
    }
}      

// for player status ------------------------------------------------------    

else if (object == player && [keyPath isEqualToString:@"status"])
{
    if (player.status == AVPlayerStatusFailed)
    {
       printf("\n\n\tAVPlayer Failed\n\n");

       [ViewUtilities showAlert:AUDIO_PLAYER :AUDIO_PLAYER_FAILED_MESSAGE];
    }        
    else if (player.status == AVPlayerStatusReadyToPlay)
    {
       printf("\n\n\tAVPlayerStatusReadyToPlay\n\n");
       [player play];
        nsTimer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
    }

    else if (player.status == AVPlayerItemStatusUnknown)
    {
        [ViewUtilities showAlert:AUDIO_PLAYER :AUDIO_PLAYER_UNKNOWN];
        printf("\n\n\tAVPlayer Unknown\n\n");
    }

    if (!player)
    {
        return;
    }
}
}
}

0 个答案:

没有答案