2つの異なる再生オーディオを同時に停止するにはどうしたらいいですか?音楽が再生されているときに、別のボタンを押して同時に再生しています。私の英語のために申し訳ありません。2つの異なる演奏音声を同時に止めるにはどうしたらいいですか?
NoiseMaker
:
import AVFoundation
class NoiseMaker {
let audioFileNames = ["guitar", "applause", "monster", "bubbles"]
let players: [AVAudioPlayer?]
init() {
players = audioFileNames.map { filename in
if let url = NSBundle.mainBundle().URLForResource(filename, withExtension: "wav") {
return try? AVAudioPlayer(contentsOfURL: url)
} else {
return nil
}
}
}
func play(index: Int) {
if !players.isEmpty && index >= 0 && index < players.count {
players[index]?.play()
}
}
}
ViewController
:
import UIKit
class ViewController: UIViewController {
let noiseMaker = NoiseMaker()
@IBAction func playSound(sender: UIButton) {
noiseMaker.play(sender.tag)
}
}
コードにリンクを投稿したり、コードタグを使用したり、あなたのコードを質問に入れたりしないでください。 –