Skip to content
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

Cannot change audio volume on Oculus Quest 2 #296

Closed
massimo-bortolamei-hegias opened this issue Jul 7, 2021 · 5 comments
Closed

Cannot change audio volume on Oculus Quest 2 #296

massimo-bortolamei-hegias opened this issue Jul 7, 2021 · 5 comments
Labels
feature-request New feature or request

Comments

@massimo-bortolamei-hegias

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

@zhinang-amazon
Copy link
Contributor

Hi @massimo-bortolamei-hegias,

Thanks for reporting the issue, and it's interesting to see that you are bridging our Android SDK to Unity and building on Quest. We will take a look and get back to you.

@massimo-bortolamei-hegias
Copy link
Author

Hello @zhinang-amazon , do you have any feedback on this issue? The custom solution that I got from Photon (and enhanced myself) is not working anymore since latest Oculus Quest software update :(

@massimo-bortolamei-hegias
Copy link
Author

Hello @zhinang-amazon , I investigated quite a lot about what is happening and I believe I could solve the issue if I had access to the AudioTrack that is created by chime to stream the audio into.
Would it be possible to expose a reference to such AudioTrack through the API ? I believe I could then control its volume directly with setVolume and work around this problem.
Alternatively, if I could get access to the repo from which the amazon-chime-sdk-media is compiled, I could probably fork and do everything by myself.
Eventually I would be happy to share my changes in both SDK with the Chime Android Team, so that you could support even the Quest Platform without any additional effort.
I'm looking forward to your answer,
Thank you

@alnlau
Copy link
Contributor

alnlau commented Oct 5, 2021

Hello,

We currently do not expose the AudioTrack. We'll consider exposing the audio as a feature request and update this when we have more information about this.

@alnlau alnlau added the feature-request New feature or request label Oct 5, 2021
@awsvikas awsvikas added this to Tell Us What You Need in Amazon Chime SDK Project Board Feb 23, 2022
@linsang21
Copy link
Contributor

Audio stream type is supported at the latest 0.16.0 release. Also you can check out the README for how to use it, here. Gonna close the issue, feel free to open new one if you needed.

@georgezy-amzn georgezy-amzn moved this from Tell Us What You Need to Shipped in Amazon Chime SDK Project Board Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Development

No branches or pull requests

4 participants