tags:

views:

22

answers:

0

Hi guys,

I am getting a problem when I am converting an NSMutableData to NSString.

- (void)downloadOutstandingFileSounds:(NSString *)urlString
{

        NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] 
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                timeoutInterval:60.0];
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
        if (theConnection) 
        {
            currentFileDataContainer = [[NSMutableData data] retain];
        }
        else 
        {
            NSLog(@"failed attempt to download resource at: %@", [NSURL URLWithString:urlString] );
        }

    [[NSNotificationCenter defaultCenter] postNotificationName:@"OutstandingFileSoundsDownloaded" object:self];

}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[currentFileDataContainer setLength:0];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[connection release];
[currentFileDataContainer release];

NSLog(@"Connection failed! Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSMutableData *)data
{
[currentFileDataContainer appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Success! currentFileDataContainer %d bytes of file data", [currentFileDataContainer length]);
NSLog(@"%@",currentFileDataContainer);
 NSString *aStr = [[NSString alloc] initWithData:currentFileDataContainer encoding:NSASCIIStringEncoding];  
printf("\n aStr=============%s",[aStr UTF8String]);
NSURL *downloadedURL = [NSURL URLWithString:aStr];
AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:downloadedURL error:nil];
avPlayer.volume = 50;
[avPlayer prepareToPlay];
[avPlayer play];
}

where I am getting the currentFileDataContainer length and content when I am converting it into string and when I print the value in the string nothing is shown in the console.

can anyone help me how to get rid of this.

Thanks in advance, Monish.