我正在尝试为iPhone开发应用程序。这是我的第一个iPhone应用程序,所以请耐心等待。我目前很容易将来自Icecast的mp3音频流式传输到android。但是我无法弄清楚如何对iPhone做同样的事情。我读过很多关于HLS的文章,但是我可以从Icecast那里做到吗?或者还有其他选择吗?
答案 0 :(得分:1)
AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[songPlayer currentItem]];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
[player play];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:@"status"]) {
if (songPlayer.status == AVPlayerStatusFailed) {
NSLog(@"AVPlayer Failed");
} else if (songPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"AVPlayerStatusReadyToPlay");
} else if (songPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
}
}