tags:

views:

33

answers:

1

Hi friends I got a question. Here it is:

I want to play an mp3 song which first will be downloaded locally and then it will be played.

I have written following code. Please have a look:-

NSURL *url = [NSURL URLWithString:[songURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];    
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
NSURLResponse *response;        
NSError *error;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *pathForSoundFile  = [[paths objectAtIndex:0] stringByAppendingString:[NSString stringWithFormat:@"/my.mp3"]];
NSLog(@"%@",pathForSoundFile);

NSURL *myURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",pathForSoundFile]];

[self  playPreviewMethod];

-(void)playPreviewMethod
{
    [songPreview play];
}

What i guess is that the file is not downloaded or converted in the mp3 format. Please help!

A: 

is your file getting downloaded?

Check out the folder Library-> applicationSupport-> iPhone Simulator -> your folder-> Documents

Chck out whether the file is downloaded. and if the file is getting downloaded then check out the name of the file whether it is my.mp3 or not. I think theres the problem you are not passing correct name while playing the file.

hAPPY cODING...

Suriya
@Suriya.Yes The file was getting downloaded by the name of my.mp3 but its size was very small. But Now I directly passing the URL to play the song, not storing it locally. It is working fine. Thanks for your reply :-)
Harsh
Getting a vote is the best thanks
Suriya