Wie music spielen und stoppen mit single button wie in itunes.Wenn die taste gedrückt ist und die gleiche taste erneut gedrückt sollte die musik zu stoppen.make play und stop musik mit der gleichen taste swift
var audioplayer = AVaudioPlayer
@IBAction func play(_ sender: Any) {
do
{
audioPlayer = try AVAudioPlayer (contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "bensound", ofType: "mp3")!))
audioPlayer.prepareToPlay()
audioPlayer.play()
audioPlayer.stop()
}
catch {
print ("error")
}
}