Sto usando AVPlayer per riprodurre audio da un URLstato AVPlayer sempre AVPlayerStatusReadyToPlay
In viewDidLoad:
self.playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:imageText]];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
[player play];
Observer
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:@"status"]) {
if (player.status == AVPlayerStatusReadyToPlay) {
//[playingLbl setText:@"Playing Audio"];
NSLog(@"fineee");
[playBtn setEnabled:YES];
} else if (player.status == AVPlayerStatusFailed) {
// something went wrong. player.error should contain some information
NSLog(@"not fineee");
NSLog(@"%@",player.error);
}
else if (player.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
}
}
ma il giocatore a volte è bloccato e non lo fa riprodurre l'audio, ma anche lo stato è AVPlayerStatusReadyToPlay. Non entra mai in AVPlayerStatusFailed o AVPlayerItemStatusUnknown. Dato che voglio gestire l'errore di AVPlayer, deve entrare anche in questi. Per favore aiuto!!
Grazie super :) Sei il salvatore :) – Srikanth
GRAZIE !!! Questo codice mi ha aiutato! –
** Esattamente ** quello che stavo cercando, grazie! – zpasternack