Audio is not playing using this approach. The play() function is executing without any error. Please help
var audioPlayer = AVAudioPlayer()
let path = Bundle.main.path(forResource: "a", ofType: "mp3")
@State var isPlaying : Bool = false
var body: some View {
Button(action: {
self.isPlaying.toggle()
let url = URL(fileURLWithPath: self.path!)
do {
self.audioPlayer = try AVAudioPlayer(contentsOf: url)
self.audioPlayer.prepareToPlay()
self.audioPlayer.play()
}catch {
print("Eror")
}
}, label: {
if isPlaying {
Image(systemName: "pause")
.font(Font.system(.largeTitle).bold())
}else {
Image(systemName: "play.fill")
.font(Font.system(.largeTitle).bold())
}
})
}