Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Last active June 4, 2017 15:45
Show Gist options
  • Select an option

  • Save takoikatakotako/3a0e0e810cc3af5c4ed575ce4f4611c5 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/3a0e0e810cc3af5c4ed575ce4f4611c5 to your computer and use it in GitHub Desktop.
play music
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer : AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
let soundFilePath : String = Bundle.main.path(forResource: "BGM_a", ofType: "mp3")!
let fileURL : URL = URL(fileURLWithPath: soundFilePath)
do{
audioPlayer = try AVAudioPlayer(contentsOf: fileURL)
}
catch{
}
//numberOfLoopsに-1を指定すると無限ループする。
audioPlayer.numberOfLoops = -1
audioPlayer.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment