UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 77 Project 23 can't hear caf sound files

Forums > 100 Days of Swift

Anyone had this issue? I added the sound code to hear the "swoosh" sounds when running my finger over the screen. I can't hear them. Tried both a real iPad and a simulator. I can press play on the caf files in xcode and hear the swoosh sound so I think the files are OK, but for some reason I can't hear them in the app.

2      

Thanks @AreejAnujm.

Check volume settings: on real ipad: not muted and I can play youtube video in browser and hear it just fine. adjusting volume with buttons changes volume of video

on simulator: Mac is playing audio OK. I can hear email notification sounds etc. tried bouncing audio between mac studio and studio display. both worked for mac sounds but neither mattered for the game in the simulator. I can adjust ipad simulator volume by pressing <CMD>+<up arrow>/<CMD>+<down arrow>. I can see the slider "adjusting" volume as I do that. Playing youtube video in safari plays audio pretty quietly and adjust volume with controls doesn't change the volume so not sure about that.

Debug sound code: I added print statements to that code and I can see the statements in the debug console in xcode. Could be something here but I think the code is fine. Pretty much just cut and paste from Paul's page with the video content.

Test with different sounds: A little further along in the development so there are a lot of additonal sounds coded in. I'm not hearing any of them.

Check Simulator Settings: see check volume settings above ... unless there's something additional I'm not understanding.

Which leaves me with "Audio Session Configuration". Can you elaborate on that more? I did some googling but I'm not sure what you're talking about.

Here's some of my code in GameScene.swift:

  . . .
func playSwooshSound() {
        isSwooshSoundActive = true

        let randomNumber = Int.random(in: 1...3)
        let soundName = "swoosh\(randomNumber).caf"

        let swooshSound = SKAction.playSoundFileNamed(soundName, waitForCompletion: true)

        run(swooshSound) { [weak self] in
            self?.isSwooshSoundActive = false
        }
    }
. . . 
  override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: self)
        activeSlicePoints.append(location)
        redrawActiveSlice()

        if !isSwooshSoundActive {
            playSwooshSound()
        }
    . . .

most of that code comes from this video (or the videos after it)

2      

OK. This is really frustrating. I pushed the code up to github and pulled it down to my work Macbook and it works fine in a simulator on that machine. I can't connect my iPad to my work Mac so I can't test on a real device from there but the fact that it works in the simulator means either there's a problem with the simulator's audio on my personal Mac or there's some issue with the sound on my personal Mac.

I feel like it has to be related to xcode on my personal mac because normal sound is fine on it. I can hear sound in videos in safari and when new mail comes in I get the system sound etc. So the mac is not muted. Also, mac sound settings wouldn't affect my real iPad. Just not sure what the issue is with sound in my apps in Xcode on my personal Mac

2      

Thanks for your replay @AreejAnjum. Made some forward progress! I had tried putting the AVAudioSession. type code in the app earlier but I guess I didn't do it right because with debug statements I realized it wasn't actually being called. So, properly adding that in I now have sound when playing to my real iPad. Not sure why I didn't need this on my work Mac though. Playing the game on an iPad simulator from my work mac was playing sound already.

Still no sound from the simulators though. I now have sound adjustment working on the simulators. FOr some reason <CMD>+<down arrow> increases the volume and <CMD>+<up arrow> decreased the volume level. Witht he volume all the way "up" I still can't hear sounds from my app even though youtube videos in safari are blaring away. I'll go through the rest of your list to see if I can figure anything else out. Here's my code if you want to take a look at it. Maybe you can see something else I've missied.

Thanks,

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.