【问题标题】:Matt Gallagher's AudioStreamer in iPhone - unable to configure network read streamiPhone 中 Matt Gallagher 的 AudioStreamer - 无法配置网络读取流
【发布时间】:2012-01-11 13:05:38
【问题描述】:

我正在使用 Matt Gallagher 的算法在 iOS 中执行 mp3 流式传输,但有时当您暂停应用程序并在一段时间后恢复歌曲时,会弹出一条消息:“无法配置网络流读取”。我已经分析了代码,但我不知道如何解决这个错误。有没有人设法更好地处理这个错误?

Matt Gallagher's AudioStreamer code

【问题讨论】:

  • 你有什么可以分享的答案吗?
  • 我在没有互联网连接时遇到了这个问题。这可能是一个因素吗?是在您从 wifi 移动还是移动到 wifi 时?

标签: iphone ios audio-streaming


【解决方案1】:

我在第 3 方应用程序中遇到了同样的事情,但找不到解决方案,然后我尝试了苹果的原生 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];

要捕捉玩家是否准备好玩,你可以在上面添加观察者,然后你可以像这样检查它:

- (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");
    }
}

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多