|
I want to play a sound in my SwiftUI app. It works perfectly when I ho through it in xCode but there isn't any sound on the published app or when I build it. I used this code in ViewController.swift:
I used this code in the SwiftUI view where I want the sound to play on appear:
Does anyone know what I'm doing wrong here? |
|
|
|
For the build I used the iOS simulator. I already published the first version on the App Store which means that it also applies to the physical device |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
I'm doing the exact same thing in my code; except I don't play on an appear event, I play based on a timer ending. I can't see anything wrong -- particularly makes no sense, if you're saying that this is only failing when you deploy to device. |
|
TBH I have the same issue. I mean my app doesn't play any sound (neither in iOS simulator nor in iPhone). Basically my code it's very same as yours. Also function play() returns true, means there are no issues with playing sounds. I tried older app I created which is not based on SwiftUI and It works fine, plays all sounds, the code is very same. The code I use in my SwiftUI app is:
Player.play() returns true. As you can see it is inside SwiftUI struct, but moving it to seperate file didn't help. Any suggestions? |
|
|
|
In my case I always double checked the volume and it wasn't mute. I even added the AVFoundation.framework in the General setting. Now it works on the preview built but not on the newly updated AppStore app. I even tried it with multiple devices but it still doesn't play anything. Does anyone know if I'm missing something here? |
|
Try using in you View
This is my
and use in
This works maybe missing |
|
This doesn't seem to work for me. sound is apperently not declared and shows an error. If I just try to add
the .onAppear functionality of my "subview" doesn't work anymore. |
|
Hi Katarina
I put the code using
and when appears it plays the sound. Try it with your You need the |
|
Thanks! I tried this now. It works on the simulator. I'm crossing my fingers that it will work on the updated App Store version |
|
So the new version is uploaded but it still won't work :( does anyone know if I'm missing a setting that's crucial for app store versions? |
|
I would check how the file sound is added to your project. When you select the file in Xcode do you see it being part of the target? I would guess the problem is that the sound is missing in the App Store version. |
|
It works now. The problem was silent mode which preveneted sounds from being played. For some reasons the issue went away in the next version without me changing the code for all of the sound views. Don't know why but at least it works now |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.