Very short snippet: streaming mp3 file su Apple iPhone
martedì 1 dicembre, 2009Un'alternativa davvero semplice per eseguire uno streaming di un file mp3 su Apple iPhone potrebbe essere:
-
// Utilizzare AVFoundation Framework e nell'header file (.h) aggiungere
-
// #import <AVFoundation/AVFoundation.h>
-
-
// Nell'implementazione
-
// inserite l'url del file mp3
-
-
-
AVAudioPlayer * audioPlayer = [[AVAudioPlayer alloc] initWithData:dataRaw error:nil];
-
-
[audioPlayer play];
Ora, non direttamente correlato a questo "snippet", guardate come è facile con la (tanto odiata) sintassi a parentesi quadre di Objective-c ridurre tutto ad una sola riga:
-
AVAudioPlayer * audioPlayer = [[AVAudioPlayer alloc] initWithData: [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.server.com/test.mp3" ] ] returningResponse:nil error:nil] error:nil];
-
[audioPlayer play];
Indentando il codice un po' meglio si ha:
-
AVAudioPlayer * audioPlayer =
-
[
-
[AVAudioPlayer alloc]
-
]
-
returningResponse:nil error:nil]
-
error:nil];
-
[audioPlayer play];
Questione di gusti, ovviamente...










19

Non ci sono commenti per questo Post
Lascia un commento