Je veux jouer une chanson mp3 qui sera d'abord téléchargée localement et ensuite elle sera jouée.Ecouter Mp3 après l'avoir enregistré localement sur l'iPhone
J'ai écrit le code suivant:
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];
}
Ce que je pense est que le fichier est téléchargé ou pas converti au format mp3.
Où télécharger je commence à vous ne voyez pas de code à partir de téléchargement du fichier ... – TheSquad
NSURL * url = [NSURL URLWithString: [songURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]?; NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL: URL cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 60.0]; [request setHTTPMethod: @ "POST"]; NSURLResponse * réponse; Erreur NSError *; NSData * result = [NSURLConnection sendSynchronousRequest: requête returnResponse: & erreur de réponse: & erreur]; songURL => Cette variable contient l'URL de la chanson – Developer