PDA

View Full Version : Client restart in Unity on Android breaks audio (SDK 3.0.3.2)



jdwilder
December 5th, 2016, 10:10 PM
Hi,

It appears that all audio output and capture fails for the Unity integration on Android, when attempting to restart a client.

For instance, this simple modification to TS3_Client_Example effectively disables audio:



class TS3_Client_Example
{
...
void connect()
{
...
// Add these lines to the end to stop then restart the client:
ts3_client.StopClient();
ts3_client.StartClient(serverAddress, serverPort, serverPassword, nickName, ref defaultChannel, defaultChannelPassword);
}


This works on PC, but not on Android. It also appears the client is connecting to the server correctly (the server reports the disconnect and reconnect), but just the audio is broken (the server does not detect captured audio).

jdwilder
December 5th, 2016, 11:57 PM
As usually happens, I find a fix after posting...

I took a look at the disassembled source for TeamSpeakUnity.jar included with the sample.

It appears that TeamSpeakWrapper.InitClientLib constructs an instance of AudioThread just once, and stores it statically. That works, but since the AudioThread constructor indirectly calls startPLAY and startREC, subsequent calls to InitClientLib and ClientStart do not initiate playback and recording.

Since I can't change the compiled .jar, I'm using a work-around in TeamSpeakClient.StartClient that explicitly restarts audio on secondary calls.

For reference, the fix changes this:


...
if (!cbsInitialized)
...
teamSpeakWrapper.CallStatic("InitClientLib");
...


To this:


...
bool wasCbsInitialized = cbsInitialized;
if (!cbsInitialized)
...
teamSpeakWrapper.CallStatic("InitClientLib");
if (wasCbsInitialized)
teamSpeakWrapper.CallStatic("StartAudio");
...

Sheepstyle
February 9th, 2018, 04:49 PM
Thank you VERRY VERRY VERRY Much, this solved my Problem.