Skip to content

Instantly share code, notes, and snippets.

@takopom
Created September 1, 2016 08:16
Show Gist options
  • Save takopom/0f6b5927e941783d3f05c7b1aa4ccfe0 to your computer and use it in GitHub Desktop.
Save takopom/0f6b5927e941783d3f05c7b1aa4ccfe0 to your computer and use it in GitHub Desktop.
Swift - httpの音楽ファイルをAVAudioPlayerで再生する
// httpの音楽ファイルを非同期で取得して再生する
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in
let url = NSURL(string: "http://xxxxx.m4a")
let data = NSData(contentsOfURL: url!)
do {
self.player = try AVAudioPlayer(data: data!)
self.player.prepareToPlay()
self.player.play()
} catch {
NSLog("cannot play audio")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment