-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External audio stops right after fortune wheel initialization #24
Comments
I don't have a Macbook/iPad with me right now to check this out. Could you please try this on your viewDidLoad: |
I already tried that but no luck. It seems to me that |
They both use AVAudioSession. Try to add it to AppDelegate to didFinishLaunchingWithOptions. Try other options like here: https://stackoverflow.com/questions/32198013/avaudioengine-stops-devices-background-audio |
If it does not help, the only problem I see is that, after collisions and sounds stop, the wheel should notify others. try AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation) The reason for this is that other apps playing music in the background will know when to turn their audio back on when you deactivate yours. Otherwise, your background music won't turn back on. If you cannot find the workaround, I will look into it in the coming days. |
Well, the problem is not with resuming background music from Music app. The problem I wanted to focus is:
If other sound would stop when the wheel spinning animation started, that wouldn't be a problem. It's the intended behaviour after all. The issue is, I just navigate to the wheel view controller and sound from other source stops immediately. Then there is a crash 💥 as per following sequence:
|
I found a good relevant comment here: https://stackoverflow.com/a/55505717/3687801
|
@sh-khashimov Can you please check the PR? Would be nice if you can verify and merge. |
Please be patient. I will check your merge as soon as will have time. |
adding this code:
do {
try AVAudioSession.sharedInstance()
.setCategory(.playback, options: .duckOthers)
try AVAudioSession.sharedInstance()
.setActive(true)
} catch {
print(error)
} to AppDelegate didFinishLaunchingWithOptions or to
@IBOutlet weak var fortuneWheel: SwiftFortuneWheel! {
didSet {
do {
try AVAudioSession.sharedInstance()
.setCategory(.playback, options: .duckOthers)
try AVAudioSession.sharedInstance()
.setActive(true)
} catch {
print(error)
}
}
} Fix everything. However, the problem caused that instead of an engine.start() there should be an engine.prepare() method. |
Would you mind closing this issue? |
Navigating to a view controller that hosts a
SwiftFortuneWheel
stops any external audio that might have been being played within Music application.SwiftFortuneWheel/Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayerManager.swift
Line 36 in 8836695
Commenting the
init()
ofAudioPlayerManager
seems to fix this problem. But this might have other consequences somewhere else.Note: I also need the collision sound effect to be enabled.
The text was updated successfully, but these errors were encountered: