【发布时间】:2016-12-03 06:54:33
【问题描述】:
我尝试过从流媒体播放音频。它适用于某些 URL,但对于某些具有某些 URL (http://listen.radionomy.com/almightyradiohindi) 的 URL,即使播放器状态为 = AVPlayerStatusReadyToPlay,它也会失败。如果我将相同的 URL 放在浏览器中不起作用,那么它也不起作用。但我认为播放器不应该将状态显示为 = AVPlayerStatusReadyToPlay。我面临管理它的问题。例如,我如何知道 AVPlayer 对哪个流媒体 URL 有效?
我的代码:
-(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]; [玩家玩];
-
你发现问题了吗?
-
@Ravi 你有什么解决办法吗?
标签: ios objective-c audio buffer avplayer