Bonjour
I use this code in Xcode 14
import AVFoundation
class Jouer{
var audioPlayer: AVAudioPlayer?
func playAudio() {
let sound=Bundle.main.url(forResource: "musique.mp3, withExtension: "mp3")
guard let url = sound else {
print("Audio file not found")
return
}
if FileManager.default.fileExists(atPath: url.path) {
print("Audio file exists")
} else {
print("Audio file not found")
}
do {
let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSession.Category.playback)
audioPlayer = try AVAudioPlayer(contentsOf: url)
guard let audioPlayer = audioPlayer else {
return
}
audioPlayer.prepareToPlay()
audioPlayer.play()
if audioPlayer.isPlaying {
print("sound playing")
} else {
print("problem sound not playing")
}
} catch {
print("Error playing audio: \(error.localizedDescription)")
}
}
}
there is no error but I can hear no sound no sound and volume is ok
the file musique.mp3 is well in the project
What am I missing?
thanks for your help