Fragmento muy breve: la transmisión de archivos mp3 en el iPhone de Apple

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

XHTML PERMISO TAG: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> código de inserción:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Dejar de SOPA