Skip to content

Instantly share code, notes, and snippets.

@leopard627
Created June 7, 2018 16:31
Show Gist options
  • Save leopard627/3a2cd683591b66866d7987ec150a9958 to your computer and use it in GitHub Desktop.
Save leopard627/3a2cd683591b66866d7987ec150a9958 to your computer and use it in GitHub Desktop.
import UIKit
import AVFoundation
var audioPlayer:AVAudioPlayer!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let path = Bundle.main.path(forResource: "rain.mp3", ofType:nil)!
let url = URL(fileURLWithPath: path)
do {
audioPlayer = try AVAudioPlayer(contentsOf: url)
audioPlayer?.play()
} catch let error {
print(error.localizedDescription)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment