当前位置: 动力学知识库 > 问答 > 编程问答 >

swift - What is the simplest way to play a 1-second sound in iOS?

问题描述:

What is the easiest library / framework to use?

I see lots of libraries but don't know which the industry standard is.

网友答案:

Here is some working Code for you to make it simpler. This works perfectly in my game.

import AVFoundation

var bgMusic:AVAudioPlayer = AVAudioPlayer()

override func viewDidLoad() {
    super.viewDidLoad()

var bgMusicURL:NSURL = NSBundle.mainBundle().URLForResource("yourTune", withExtension: "mp3")!
bgMusic = AVAudioPlayer(contentsOfURL: bgMusicURL, error: nil)
bgMusic.numberOfLoops = 1
bgMusic.prepareToPlay()
bgMusic.play()

}

Make sure to change the name of your tune! :)

网友答案:

You don't need an additional library to play sounds in iOS. Just use what is provided to you by the corresponding SDK: AVAudioPlayer.

分享给朋友:
您可能感兴趣的文章:
随机阅读: