Last active
June 4, 2017 15:45
-
-
Save takoikatakotako/3a0e0e810cc3af5c4ed575ce4f4611c5 to your computer and use it in GitHub Desktop.
play music
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
| 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