-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Describe the bug
Pressing the hardware volume buttons on the quest, when the audiovideo has started, does not change volume of the call, and also does not show quest's UI for volume control anymore.
It is my understanding that when audiovideo starts, the mode gets changed to MODE_IN_COMMUNICATION
, but the quest apparently directs everything towards STREAM_MUSIC
.
With the following script I was able to catch the volume change triggered by hardware button, and verify that it happens in STREAM_VOICE_CALL
. I then tried to replicate such change into STREAM_MUSIC
as well.
public class AndroidNativeVolumeService : MonoBehaviour
{
AndroidJavaObject volumeSync;
void Start()
{
AndroidJavaClass app = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = app.GetStatic<AndroidJavaObject>("currentActivity");
volumeSync = new AndroidJavaObject("com.hegias.socketio.VolumeSync", activity);
volumeSync.Call("Enable", true);
}
void OnDestroy()
{
volumeSync.Call("Enable", false);
}
}
public class VolumeSync {
private android.database.ContentObserver observer;
Activity activity;
public VolumeSync(Activity activity) {
this.activity = activity;
}
public void Enable(boolean on) {
if (on) {
if (observer == null) {
observer = new ContentObserver(activity.getApplicationContext(), new android.os.Handler());
activity.getApplicationContext().getContentResolver().registerContentObserver(android.provider.Settings.System.CONTENT_URI, true, observer);
}
} else {
if (observer != null) {
activity.getApplicationContext().getContentResolver().unregisterContentObserver(observer);
observer = null;
}
}
}
class ContentObserver extends android.database.ContentObserver {
private AudioManager audioManager;
public ContentObserver(Context context, android.os.Handler handler) {
super(handler);
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
@Override
public boolean deliverSelfNotifications() {
return false;
}
@Override
public void onChange(boolean selfChange, android.net.Uri uri) {
String voiceURL = "content://settings/system/volume_voice_speaker";
if (uri.toString().equals(voiceURL)) {
int v1 = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
int v2 = v1 * audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, v2, 0);
}
}
}
}
This works partially: I have background music, and with that script I can hear its volume going up and down, meaning that I'm effectively changing the volume of STREAM_MUSIC in accordance with the pression of the hardware volume button and the change of STREAM_VOICE_CALL.
Unfortunately, while the volume of my music goes down, the voice coming from other participants stays the same (too loud).
Am I missing something from the android sdk in order to correctly change the volume?
The sample apk works on android devices (smartphones) but I am using the chime-sdk-android as external java package into a Unity project build for Quest, so there might be some differences.
Photon had the same issue, and I'm actually following their solution very closely. But maybe with chime there is something different that I'm missing
Thanks
Metadata
Metadata
Assignees
Labels
Type
Projects
Status