Created
September 1, 2016 08:16
-
-
Save takopom/0f6b5927e941783d3f05c7b1aa4ccfe0 to your computer and use it in GitHub Desktop.
Swift - httpの音楽ファイルをAVAudioPlayerで再生する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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