Ren'Py Android Port Sound Bug - Headphones

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,249
7,625
I am close to the release of the first version of my new game Stellar Crossroads. To improve accessibility, I have also created an android port of the game. For the most part this android version works well, with the exception of a sound glitch related to the headphones (audio jack).

If you start the game either with or without headphones, the sound works fine. However if you connect headphones or remove headphones, the sound stops. If you revert to how you started the game the sound isn't restored either. Note that the sound is not muted in the preferences and trying to changing it there makes no difference. It appears that the act of switching the sound output disables the audio. Does anyone have any ideas how this may be resolved?

I will also note that the problem is specifically with my game and does not seem to carry over to other renpy games on my phone.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
[...] It appears that the act of switching the sound output disables the audio. Does anyone have any ideas how this may be resolved?

I will also note that the problem is specifically with my game and does not seem to carry over to other renpy games on my phone.
This is really strange.
It would happen every time, I would have blamed Ren'Py, Android or your phone, but just for your game... Unless you've rewrote the code handling the sound, what I doubt you did, how could it only affect your game ? :/

So, are the game you tried using the same version of Ren'Py/RAPT ? It can be a bug that appeared lastly or have been solved since the version you use.
And are the sound files using the same format ? It can be a bug specific to the implementation for this specific format.

Other than that, I really don't see what could be the reason.
You're doing the same than others dev, in the same way, yet you've a different outcome... I know software too well to say that it's effectively impossible, but it looks implausible.


At worse, try a test project that would looks like this:
Code:
define testSound = "whatever.ogg"

label start:
    while True:
        menu:
           "play audio":
               play audio "whatever.ogg"
           "play sound":
               play sound "whatever.ogg"
           "play music":
               play music "whatever.ogg"
           "play variable":
               play audio testSound
           "python":
               $ renpy.play( "whatever.ogg", channel="audio" )
           "quit":
               return
[/quote]

Add other methods that could cross your mind, and the one you use if it's different. Then test on your phone to see if the outcome is always the same, or if there's a method that works.
You can also do the same to test different codec, to see if it change something or not.
 

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,249
7,625
Running Ren'Py 8.0.1
Rapt - installed late last week from within Ren'Py

I had enough problems just getting the Android port working, trust me when I say I haven't messed with the sound settings. :ROFLMAO:

The audio is a mixture of ogg (music), opus (music) and mp3 (sounds). All of these work fine (speaker or headphone) if you don't connect / disconnect the audio jack. The problem was identified by another user and I have confirmed the same behaviour. Additionally when I load up Callisto (old game) port (by The66), connecting / disconnecting the headphones works fine.

To give you an example of the behaviour, I can start the game on headphones and play along and everything is working fine. Unplug the headphones, audio stops, save the game. I can then close the app, reopen and load the save and continue on speakers. Hence 'fixing' the problem just involves reloading the game.

I tried the code you suggested above and all of the options work fine, at least until I plug / unplug the headphones. Hence it behaves exactly the same as my game.
 

Gamer_01

Member
Dec 16, 2019
205
85
I apologize if you meant to keep this discussion between the two of you, (I was just searching through posts about your new game) but I read this and I think I found a similar problem having to do with connecting/disconnecting Bluetooth on Android with Ren'py games.
I don't think it's a new problem.
When connecting a Bluetooth audio device after starting a Ren'py game I don't get sound on it.
It's been that way for years.

Although, I haven't had the problem with the Aux port. (Other than the sound being fuzzy, but I figure it's because my ear buds are old, except the sound is clear when I plug it in my iPod.)

Honestly, my brain tends to ignore sound problems. Also I don't really use the Aux port on my tablet. So the "fuzz" could just be the physical connection in the tablet.

But, like I said, I have the same problem with the sound not working when I connect to Bluetooth after starting a game.
So it probably is a fundamental problem with code. Honestly didn't think about it until now.

Not just any one game. Xavster
 
  • Like
Reactions: LongJohnnyWalker

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
Sorry for the late answer, for an unknown reason I didn't received the notification.

I tried the code you suggested above and all of the options work fine, at least until I plug / unplug the headphones. Hence it behaves exactly the same as my game.
Well, at least it seem to confirm that the problem don't come from you. That you're doing something wrong when creating the Android port, and then broke the game, yes, it's still possible. But that you just broke the audio, yet only under this particular condition, I really doubt that it's possible.

PyTom always had difficulties with Android, hence the partial support ; too many contortions to make Ren'Py being emulated, on a too wide range of OS versions, coupled to a too wide range of possible hardware combination.
It's possible that you are facing a bug specific to the 8.0.1, a regression (an old bug that reappear), or perhaps even a lack of luck and the bug is due to the combination between this version of Ren'PY and that version of Android.

If you want you can try to fill a bug report, using my example code as demonstration ; "I encounter a strange bug with the sound on Android (version X, Ren'Py version 8.0.1), here's a test code that demonstrate it."
 

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,249
7,625
Firstly thank you for the responses.

I have also redone the Android port with Ren'Py 8.0.2, however the problem still persists. Once the game is publicly released next Friday 16th, I will likely share my code for the Android port to allow another to build the port. This should identify whether the issue is a result of the code or the Ren'Py / rapt combo I am employing. It's not a game breaking bug, just a little inconvenient to those that want to switch audio output mid game.

Please note that the error is apparent when connecting / disconnecting headphone plug into phone socket. It may also occur with Bluetooth, however don't have the relevant hardware to test.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
Please note that the error is apparent when connecting / disconnecting headphone plug into phone socket. It may also occur with Bluetooth, however don't have the relevant hardware to test.
Thinking about it, I perhaps found the cause, but it's not something that you'll be able to solve.

Ren'Py is known to automatically shutdown sound when there's no devices to play it. And I guess that Android is sending a notification when you unplug the headphone.
So my guess is that Ren'Py misunderstand this notification, thinking that there's now no sound device and therefore muting everything. In the same time, it correctly discard the "hey, headphone have been plugged in" notification, since the notification is insignificant for it ; Android devices are expected to have their own speakers, adding a new sound device do not have an impact on the game.