1

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;
    }
}
}
}
3
  • Hey I have the same issue.. Did you find any solution for this yet?
    – Malav Soni
    Jan 19, 2016 at 13:10
  • Yes I solved this issue, I will share code with you soon..
    – Ravi
    Jan 20, 2016 at 10:39
  • @Malav Soni, Set buffering on audio player.
    – Ravi
    May 19, 2016 at 9:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.