Sunday, August 2, 2015

How to Play Audio in Swift


var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3"){
            var filePathUrl = NSURL.fileURLWithPath(filePath)
            audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)

            audioPlayer.enableRate=true

with this code

File -> add new file -> select audio file -> move to "supporting files " on Navigator.
the file is located to "movie_quote" 


2, 

    @IBAction func FastButton(sender: UIButton) {
        audioPlayer.stop()
        audioPlayer.rate = 2.0
        audioPlayer.play()


Action on User Interface Button with above code.
rate  enable to change the pitch.

today's Udacity's lecture.

No comments:

Post a Comment