I have an mp3 track at the URL http://mysite.com/MP3/track1.mp3 . Uploading it to the local path using NSURLConnection and NSDocumentDirectory. I would like to start playing on this track as soon as possible, and not after it is fully loaded. Is there any time for this? I tried to set the size limit to "X", and as soon as the download hits this number to start playing the track. But this only happens until the moment when it was initialized with the size "X". Thank you in advance.
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [self.inComingData appendData:data]; //NSLog(@"inComingData: %d", [inComingData length]); CGFloat dataLen = [[NSString stringWithFormat:@"%d",[self.inComingData length]] floatValue]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [paths objectAtIndex:0]; appDelegate.path = [documentDirectory stringByAppendingPathComponent:@"track.mp3"]; [self.inComingData writeToFile:appDelegate.path atomically:YES]; // NSInteger receivedLen = [self.inComingData length]; // if ((receivedLen >= 100000) && (!checked)) { // //[appDelegate initAndPlay]; // [appDelegate playTrack]; // checked = TRUE; // } [appDelegate initPlayer]; }
source share