Objective-c , AVPlayer taking too much time to Resume play audio from URL

牧云@^-^@ 提交于 2019-12-24 11:28:10

问题


I have implemented AVPlayer. It is working fine. But many times during playing audio from URL, it stops/pauses automatically and takes very long time to resume/replay. On the other hand if I manually just pause and play it works fine means it does not take too much time to re-play. I want to resume/replay it whenever it is ready. Any suggestion will be great. Thank in advance !!!!!!!! My code :

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

来源:https://stackoverflow.com/questions/32337699/objective-c-avplayer-taking-too-much-time-to-resume-play-audio-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!