I am trying to implement AVPlayer for play audio file from URL. It is working fine. But sometimes AVPlayer stops/pauses playing and do not resume again. If I click on play button then it works fine. (it should play without user interface). (I do not want use : [player addObserver:self forKeyPath:@"rate" options:0 context:nil];) I also take help from this URL : AVPlayer stops playing and doesn't resume again. But this code has some errors. For temporary I am using this code and looks fine from my side. But I am not sure whether it is fine or not in all cases.So I want to know what should I do which handles all cases. Thanks in advance...... My code :
-(void)updateTime:(NSTimer *)timer {
// temporary code for play audio again, when player pause/stop automatically
if (player.rate==0) {
[player play];
}
currentTime = CMTimeGetSeconds(playerItem.currentTime);
duration = CMTimeGetSeconds(playerItem.duration);
[self.audioSliderBar setValue:(currentTime/duration)];
float minutes = floor(currentTime/60);
seconds =currentTime - (minutes * 60);
float duration_minutes = floor(duration/60);
duration_seconds =
duration - (duration_minutes * 60);
NSString *timeInfoString = [[NSString alloc]
initWithFormat:@"%0.0f:%0.0f",
minutes, seconds ];
self.audioCurrentTimeLabel.text = timeInfoString;
}