I cannot seem to get this link:
https://api.soundcloud.com/tracks/54507667/stream
to work with the AVAudioPlayer. I have tested it in a Souncloud API started project and it seems to work just fine, however, when I try to implement it on my own it doesn't seem to work.
The error I get:
unrecognized selector sent to instance 0x9245d40 2013-01-04 17:56:04.699 CollectionViewTest[17023:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x9245d40' * First throw call stack:.....
The code:
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");
The streamURL prints as expected, and then the program crashes.
the tests are not printed. When everything else is commented out, and the NSURLRequest is left, it still crashes. When I comment the whole block of code out, everything compiles and runs.
I now have attempted this:
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];
This also returns the length error, I am at a loss on what could be causing this...
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] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x928a470' * First throw call stack: