Ich habe versucht, Audio vom Streaming zu spielen. Es funktioniert gut mit einigen URL aber für einige mit einer URL (http://listen.radionomy.com/almightyradiohindi) scheitert es sogar Spieler Status kommt = AVPlayerStatusReadyToPlay. Wenn ich dieselbe URL anlege, die im Browser nicht funktioniert, dann funktioniert es auch nicht. Aber ich denke Spieler sollten den Status nicht als = AVPlayerStatusReadyToPlay anzeigen. Ich stehe vor dem Problem, es zu bewältigen. Wie kann ich zum Beispiel wissen, für welche Streaming-URL der AVPlayer funktioniert oder nicht?iOS - AVPlayer Streaming Audio für einige URL
Mein Code:
-(void)viewDidLoad {
NSURL *url = [[NSURL alloc] initWithString:urlString];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
avPlayer = [AVPlayer playerWithPlayerItem:anItem];
[avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == avPlayer && [keyPath isEqualToString:@"status"]) {
if (avPlayer.status == AVPlayerStatusFailed) {
NSLog(@"\n\n **** AVPlayer Failed ***\n\n");
}
else if (avPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"\n\n **** AVPlayer Ready to Play ****\n\n");
[avPlayer play];
}
else if (avPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"\n\n **** AVPlayer Unknown \n\n ****");
}
}
}
NSURL streamingURL * = [NSURL URLWithString: URL_STRING]; NSLog (@ "% @", streamingURL); player = [AVPlayer playerWithURL: streamingURL]; [Spieler spielen]; –
Haben Sie das Problem herausgefunden? – Artur