【发布时间】:2013-01-06 03:48:39
【问题描述】:
我似乎无法获得此链接:
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 0x928a4702013-01-05 13:46:16.546 CollectionViewTest[28224:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSURL 长度]:无法识别的选择器发送到实例 0x928a470” * 首先抛出调用栈:
【问题讨论】:
标签: ios avaudioplayer