###前提・実現したいこと
swift初心者ですが、XCODE と swift3で以下のことがしたいです。
———————————
ABCの3つのボタンがあり、
Aを押しながらCを押すと1.mp3が再生され、
Bを押しながらCを押すと2.mp3が再生される
———————————
しかし、ひとつひとつのボタンを押して音が出せても
複数のボタンを押した時の処理がわかりません。
よろしくお願いします。
###該当のソースコード
import UIKit
import AVFoundation
class ViewController: UIViewController {
var sound01: AVAudioPlayer = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let musicFile01 = Bundle.main.path(forResource: "1", ofType: "mp3") do{ try sound01 = AVAudioPlayer(contentsOf: URL (fileURLWithPath: musicFile01!)) sound01.prepareToPlay() } catch { print(error) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //音再生 @IBAction func play00(_ sender: UIButton) { sound01.play() }
}
回答1件
あなたの回答
tips
プレビュー