Una alternativa muy simple de ejecutar una secuencia de un archivo mp3 en el iPhone de Apple podría ser:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | / / Use Marco AVFoundation y archivos de cabecera (. H) para añadir / / # Importar <AVFoundation/AVFoundation.h> / / En la puesta en práctica / / Poner la url del archivo mp3 soundFilePath = @ "http://www.server.com/test.mp3" ; NSString * soundFilePath @ = "http://www.server.com/test.mp3"; fileURL = [ NSURL URLWithString : soundFilePath ] ; NSURL * Url de Archivo = [ NSURL URLWithString: soundFilePath]; request = [ NSURLRequest requestWithURL : fileURL ] ; NSURLRequest petición * = [ NSURLRequest requestWithURL: Url de Archivo]; dataRaw = [ NSURLConnection sendSynchronousRequest : request returningResponse : nil error : nil ] ; NSData dataRaw * = [ NSURLConnection sendSynchronousRequest: solicitud returningResponse: error cero: nil]; [ [ AVAudioPlayer alloc ] initWithData : dataRaw error : nil ] ; AVAudioPlayer AudioPlayer * = [[AVAudioPlayer alloc] initWithData: error dataRaw: nil]; ; [AudioPlayer juego]; |
Ahora bien, no relacionados directamente con este "fragmento", mira lo fácil que es con el (odiado) en la sintaxis de corchetes de Objective-C para reducir todo a una sola línea:
1 2 | [ [ AVAudioPlayer AVAudioPlayer AudioPlayer * = [[AVAudioPlayer ; [AudioPlayer juego]; |
Sangrar el código un poco "mejor, tenemos:
1 2 3 4 5 6 7 8 9 10 | * AudioPlayer = AVAudioPlayer [ [ALLOC AVAudioPlayer] NSURLConnection initWithData: [ NSURLConnection NSURLRequest sendSynchronousRequest: [ NSURLRequest NSURL URLWithString : @ "http://www.server.com/test.mp3" ] requestWithURL: [ NSURL URLWithString: @ "http://www.server.com/test.mp3"] ] error : nil ] returningResponse: error cero: nil] ] ; error: nil]; ; [AudioPlayer juego]; |
Cuestión de gustos, por supuesto ...











No hay comentarios para esta entrada
Deja un comentario