-
Notifications
You must be signed in to change notification settings - Fork 401
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
Android Background music continues to play, after app is minimized #1828
Comments
I tried to reproduce this with this code. function love.load()
rolling = love.audio.newSource("test.mp3", "stream")
rolling:setLooping(true)
end
function love.draw()
love.graphics.print(tostring(rolling:isPlaying()), 64, 64)
end
function love.mousereleased()
if rolling:isPlaying() then
rolling:pause()
else
rolling:play()
end
end Then run the app, tap anywhere to start the audio, then press the home button. I can't reproduce it on Samsung Galaxy A52s (SM-A528B) and Pixel 3 AVD, both running Android 12. Audios are paused when I back to home. Are there any specific instruction on how to reproduce this? |
Thanks for looking into it. I can confirm your above code works as expected. It helped me find the source of the culprit, however. In my code the local play = false
function love.load()
rolling = love.audio.newSource("test.mp3", "stream")
rolling:setLooping(true)
end
function love.draw()
love.graphics.print(tostring(rolling:isPlaying()), 64, 64)
end
function love.mousereleased()
play = not play
end
function love.update()
if play then
rolling:play()
else
rolling:pause()
end
end |
In that case, I think there's another 1 frame that slip through just after LOVE receives event that it should pauses all sources. So, the flow will look like this:
I think the actual solution to this is using OpenAL-soft's |
The frame slipping and replaying seems plausible. I my initial claim that Using the following update function, function love.update()
if play then
if not rolling:isPlaying() then
rolling:play()
print("play")
end
else
rolling:pause()
end
end
I would agree current solution seems a bit like a hack. As for the fallback in addition to pausing, it might make sense to also set the volume of all playing sources to 0 and restore the volumes again on regaining focus. This could lead to other problems, but they seem less annoying than background music still playing. But that's just my two cents. |
I'm having issues that background music continues to play after the app is minimized.
During my investigation on how to fix or work around it I found the following code:
love/src/modules/event/sdl/Event.cpp
Line 626 in 878ad78
I debugged to confirm the code is actually executed (it is). But for some reason it doesn't actually pause the audio sources. The source type (static/stream) makes no difference.
I can replicate this behavior with two phones:
As well as with a virtual Pixel 2 with Android 12 (API 31).
My current woraround was to implement the
love.focus
handler and pause the background music manually.An other odd detail: if, in the same
love.focus
-handler, I check wether the source is playing withsource:isPlaying()
they will returnfalse
.The text was updated successfully, but these errors were encountered: