Created
June 7, 2018 16:31
-
-
Save leopard627/3a2cd683591b66866d7987ec150a9958 to your computer and use it in GitHub Desktop.
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 | |
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