@IBAction func stopMusic(_ sender: AnyObject) {
if player != nil {
player.stop()
}
else{
player.play()
}
}
答案 0 :(得分:0)
var player: AVAudioPlayer?
@IBAction func stopMusic(_ sender: AnyObject) {
if var p = player {
if p.playing {
p.stop()
}
else {
p = AVAudioPlayer()
p.prepareToPlay()
p.play()
}
}
}
override func viewDidLoad() {
player = AVAudioPlayer()
}