AgoraIO-Community / Agora_Unity_WebGL

WebGL plugin for Unity, beta release
MIT License
113 stars 25 forks source link

Muting/Umuting Remote Users Breaks Spatial Audio #324

Open moudisoubra opened 5 months ago

moudisoubra commented 5 months ago

Discussed in https://github.com/AgoraIO-Community/Agora_Unity_WebGL/discussions/323

Originally posted by **moudisoubra** July 1, 2024 When a remote user gets beyond a specific distance I mute their audio so that they cannot be heard at all using: RtcEngine.MuteRemoteAudioStream(uid, true); However when the remote user gets back within hearing distance unmuting them completely breaks Spatial Audio and they in turn start speaking at full volume.
dev-kiwicreations commented 4 months ago

How did you figure out running the spatial audio even? I've been unable to even run any of the features the SDK provides, apart from joining a channel. Here's my script: `public class LobbyVoiceAudio : MonoBehaviourPunCallbacks { private string _appID = "147f1034f33245f4abe865d9bd51fc44"; public static LobbyVoiceAudio Instance; private IRtcEngine _rtcEngine;

    private void Awake()
    {
        if (Instance)
        {
            Destroy(this.gameObject);
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(this);
        }
    }
    private void Start()
    {
        _rtcEngine = IRtcEngine.GetEngine(_appID);
        _rtcEngine.OnJoinChannelSuccess += OnJoinChannelSuccess;
        _rtcEngine.OnLeaveChannel += OnLeaveChannel;
        _rtcEngine.OnError += OnError;
    }

    private void OnError(int error, string msg)
    {
        Debug.Log($"Received Error. Code: {error}. Message: {msg}");
    }
    private void OnLeaveChannel(RtcStats stats)
    {
        Debug.Log($"Left Channel: {stats}");
    }
    private void OnJoinChannelSuccess(string channelName, uint wid, int elapsed)
    {
        Debug.Log($"Joined Channel: {channelName}");
        Hashtable hash = new Hashtable();
        hash.Add("agoraID", wid.ToString());
        PhotonNetwork.SetPlayerCustomProperties(hash);
    }

    public override void OnJoinedRoom()
    {
        _rtcEngine.EnableSoundPositionIndication(true);
        _rtcEngine.JoinChannel(PhotonNetwork.CurrentRoom.Name);
    }

    public override void OnLeftRoom()
    {
        _rtcEngine.LeaveChannel();
    }

    public void GoToTunnelChannel()
    {
        _rtcEngine.LeaveChannel();
        _rtcEngine.JoinChannel("AtlantaTunnel");
    }
    private void OnDestroy()
    {
        IRtcEngine.Destroy();
    }

    public IRtcEngine GetRTCEngine()
    {
        return _rtcEngine;
    }
}`

Am I missing any callbacks?

icywind commented 4 months ago

@moudisoubra

Discussed in #323

Originally posted by moudisoubra July 1, 2024 When a remote user gets beyond a specific distance I mute their audio so that they cannot be heard at all using: RtcEngine.MuteRemoteAudioStream(uid, true);

However when the remote user gets back within hearing distance unmuting them completely breaks Spatial Audio and they in turn start speaking at full volume.

Thanks for discovering this bug. A fix just went into the refactor11 branch. You may just update the diffs to your downloaded source, before a release comes out.

For quick test, also see updated Positional Spatial Audio Example with a new "Mute Remote" button added.

Screenshot 2024-07-23 at 3 08 14 PM

icywind commented 4 months ago

@dev-kiwicreations please see the API-examples.