no sound with AVAudioPlayer in real device and simulator in Xcode 14

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

no body to help a French newbie?

just for info,

this class is in a file, I call it from another view just so

        let player = Jouer()
        player.playAudio()

My code is wrong? No sound, no error thanks

something new I have sound in the simulator no sound in real device

I am ashamed the problem was simple i had the silent mode activated

when I said I was a newbie, I was not joking , this is more than being a newbie

no sound with AVAudioPlayer in real device and simulator in Xcode 14
 
 
Q