我似乎无法获得此链接:
https://api.soundcloud.com/tracks/54507667/stream
与 AVAudioPlayer 一起工作。我已经在一个Souncloud API 启动项目中对其进行了测试,它似乎工作得很好,但是,当我尝试自己实现它时,它似乎不起作用。
我得到的错误:
无法识别的选择器发送到实例 0x9245d40 2013-01-04 17:56:04.699 CollectionViewTest[17023:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString absoluteURL]:无法识别的选择器发送到实例 0x9245d40”*首先抛出调用堆栈:......
编码:
NSURL *streamURL = [NSString stringWithFormat:@"%@",
allDataDictionarySound[@"stream_url"], nil];
NSLog(streamURL);
NSURLRequest *request = [NSURLRequest requestWithURL:streamURL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"test:");
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
NSLog(@"test:2");
streamURL 按预期打印,然后程序崩溃。
不打印测试。当其他所有内容都被注释掉并留下 NSURLRequest 时,它仍然会崩溃。当我注释掉整个代码块时,一切都会编译并运行。
我现在尝试了这个:
NSData *_objectData = [NSData dataWithContentsOfURL:streamURL];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
NSLog(@"%@", [error description]);
else
[audioPlayer play];
这也会返回长度错误,我不知道可能导致这种情况的原因......
2013-01-05 13:46:16.536 CollectionViewTest[28224:c07] -[NSURL length]: unrecognized selector sent to instance 0x928a470
2013-01-05 13:46:16.546 CollectionViewTest[28224:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSURL 长度]:无法识别的选择器发送到实例 0x928a470”*第一次抛出调用堆栈: