dtsbourg / QRK

[PoC] Music blogging project
2 stars 2 forks source link

[SIGABRT] AVAudioPlayer loads and crashes #2

Closed dtsbourg closed 11 years ago

dtsbourg commented 11 years ago

Upon selection of a track to play, songs starts to load then app crashes here :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *track = [self.tracks objectAtIndex:indexPath.row];
    NSString *streamURL = [track objectForKey:@"stream_url"];

    SCAccount *account = [SCSoundCloud account];

    [SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:streamURL] usingParameters:nil withAccount:account sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error)
    {
        NSError *playerError;

//Crashes here
        player = [[AVAudioPlayer alloc]
//Rest is fine, have checked for (nil) on data
                  initWithData:data 
                   error:&playerError];

        if (player){[player prepareToPlay];
            [player play];}
        else NSLog(@"player is nil");
    }];
}

Wondering if not because of troubles with libSoundCloundAPI.a ...

romac commented 11 years ago

Yeah I believe that's most likely because of #1. Fix it and you should be all good :)

dtsbourg commented 11 years ago

capture decran 2013-10-21 a 21 38 11 capture decran 2013-10-21 a 21 38 20

This is the log I get when the app crashes after loading some data (typical value is 14 Megs).

The result is the same on iPhone simulator and on dev phone as well.

romac commented 11 years ago

Oh, I didn't notice that AVAudioPlayer is actually part of the iOS SDK, not SoundCloud's.

That's a weird error, and from what I gathered, nobody really knows where it comes from.

Found this and that (as you already have, I guess).

I'll ask around and see if anybody I know ever had a similar issue.

dtsbourg commented 11 years ago

Yeah i saw those posts, unfortunately not much to work with :/ I'll keep looking around, there has to be an answer somewhere ( unfortunately the Dalai Lama isn't always right : "If there's no solution, there's no problem" ;) )

Thanks again for all your precious help, keep you posted to see if I can find a workaround, since it is still strange to me why SC decided to present an AVAudioPlayer to play the music. It might be a simple interface to use but it seems more adapted to cached or saved files, and doesn't support streaming. Although parsing audio content form a network bitstream looks a bit difficult i might take a look in that direction if i really can't find any solution to this problem.

dtsbourg commented 11 years ago

Thanks to @FredericJacobs , this error was fixed. He pointed out that the request was being handled on the main thread, and while it was loading nothing was happening. As debugging was activated, it settled as an uncaught exception as the request was taking too long to fulfill. The fix included asking another thread to handle the synchronized downloading of the request through

 dispatch_async(dispatch_get_main_queue(), ^{ //data handling and allocation of player }); 

Problem solved !

FredericJacobs commented 11 years ago

You're welcome!