Sehr kurze Auszug: Streaming mp3-Dateien auf dem Apple iPhone

Eine Alternative sehr einfach zu laufen einen Stream einer MP3-Datei auf dem Apple iPhone können sein:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/ / Verwenden AVFoundation Framework und Header-Dateien (. H) hinzufügen
/ / # Import <AVFoundation/AVFoundation.h>

/ / In der Umsetzung
/ / Stellen Sie die URL der mp3-Datei
soundFilePath = @ "http://www.server.com/test.mp3" ; NSString * soundFilePath @ = "http://www.server.com/test.mp3";

fileURL = [ NSURL URLWithString : soundFilePath ] ; NSURL * fileURL = [ NSURL URLWithString: soundFilePath];
request = [ NSURLRequest requestWithURL : fileURL ] ; NSURLRequest * request = [ NSURLRequest requestWithURL: fileURL];
dataRaw = [ NSURLConnection sendSynchronousRequest : request returningResponse : nil error : nil ] ; NSData * dataRaw = [ NSURLConnection sendSynchronousRequest: returningResponse Anfrage: nil error: nil];

[ [ AVAudioPlayer alloc ] initWithData : dataRaw error : nil ] ; AVAudioPlayer * AudioPlayer = [[AVAudioPlayer alloc] initWithData: dataRaw error: nil];

; [AudioPlayer spielen];

Nun, nicht direkt auf diese "Schnipsel" im Zusammenhang, schauen, wie einfach es ist, mit den (verhassten) ist in eckigen Klammern Syntax von Objective-C, alles auf einer einzigen Zeile zu reduzieren:

1
2
[ [ AVAudioPlayer AVAudioPlayer * AudioPlayer = [[AVAudioPlayer
; [AudioPlayer spielen];

Einrücken des Codes ein bisschen besser, haben wir:

1
2
3
4
5
6
7
8
9
10
* AudioPlayer = AVAudioPlayer
[
[AVAudioPlayer alloc]
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: nil error: nil]
] ; Fehler: nil];
; [AudioPlayer spielen];

Geschmackssache, natürlich ...

Es gibt keine Kommentare für diesen Beitrag

Hinterlasse einen Kommentar

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <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