flo*_*pes 6 iphone audio-streaming ios
我使用Matt Gallagher的算法在iOS中执行mp3流媒体,但有时当你暂停应用程序时,一段时间后,恢复歌曲弹出一条消息:"无法配置网络流读取".我已经分析了代码,但我没有看到如何解决这个错误.有没有人设法更好地应对这个错误?
我对这个第三方应用程序经历了同样的事情并且找不到解决方案,然后我尝试了苹果的原生avplayer(不是avaudioplayer),它让你能够使用该功能进行流式传输:initWithURL.顺便说一句,这是类引用:http://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html
另外这里是我播放音乐的代码:
NSURL *url = [[NSURL alloc] initWithString:sourceURL];
theItem = [AVPlayerItem playerItemWithURL:url];
theItem addObserver:self forKeyPath:@"status" options:0 context:nil];
theAudio = [AVPlayer playerWithPlayerItem:mainDelegate.theItem];
Run Code Online (Sandbox Code Playgroud)
为了捕捉玩家是否准备好玩你在上面添加观察者然后你可以检查它:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == theItem && [keyPath isEqualToString:@"status"]) {
if(theItem.status == AVPlayerStatusReadyToPlay)
{
[theAudio play];
[theItem removeObserver:self forKeyPath:@"status"];
}
else if(theItem.status == AVPlayerStatusFailed) {
NSLog(@"%@" , mainDelegate.theItem.error.description);
}
else if(theItem.status == AVPlayerStatusUnknown)
NSLog(@"unknown");
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助.
| 归档时间: |
|
| 查看次数: |
2741 次 |
| 最近记录: |