Agora.io-当另一个用户离开频道并重新加入时,另一个用户的视频流挂起/停止更新

问题描述 投票:1回答:1

我尝试使用Unity制作视频流应用程序,并且我已经成功连接了两个用户,并且能够进行视频聊天和共享屏幕。现在的问题是,当另一个/第二个用户按下离开频道并再次加入时,第一个用户将看到第二个用户屏幕刚停在最后一帧。现在处理该问题的唯一方法是退出Unity播放模式,然后再次重新进入。下面是代码:

    void LoadEngine()
    {
        print("Loading Engine...");

        if (engine != null)
        {
            print("Engine already exists. Please unload it first!");
            return;
        }

        engine = IRtcEngine.GetEngine(appId);
        engine.SetLogFilter(LOG_FILTER.DEBUG);
    }

    void UnloadEngine()
    {
        print("Unloading Engine...");

        if (engine != null)
        {
            IRtcEngine.Destroy();
            engine = null;
        }
    }

    void EnableVideo(bool yes)
    {
        engine.DisableAudio();
        if (yes)
        {
            engine.EnableVideo();
            engine.EnableVideoObserver();
        }
        else
        {
            engine.DisableVideo();
            engine.DisableVideoObserver();
        }
    }

    private void JoinChannel()
    {
        print("Joining Channel...");

        EnableVideo(true);

        // add our callback to handle Agora events
        engine.OnJoinChannelSuccess += OnJoinChannelSuccess;
        engine.OnUserJoined += OnUserJoined;
        engine.OnUserOffline += OnUserLeave;
        engine.OnLeaveChannel += OnLeaveChannel;

        button_Join.onClick.RemoveListener(JoinChannel);
        button_Join.onClick.AddListener(LeaveChannel);
        button_Join.GetComponentInChildren<Text>().text = "Leave Channel";

        if (string.IsNullOrEmpty(channelName))
        {
            return;
        }

        engine.JoinChannel(channelName, null, 0);
    }

    private void LeaveChannel()
    {
        print("Leaving Channel...");

        button_Join.onClick.RemoveListener(LeaveChannel);
        button_Join.onClick.AddListener(JoinChannel);
        button_Join.GetComponentInChildren<Text>().text = "Join Channel";

        playerOne.Clear();
        playerTwo.Clear();

        engine.LeaveChannel();
        EnableVideo(false);

        engine.OnJoinChannelSuccess -= OnJoinChannelSuccess;
        engine.OnUserJoined -= OnUserJoined;
        engine.OnUserOffline -= OnUserLeave;
        engine.OnLeaveChannel -= OnLeaveChannel;
    }

    private void OnJoinChannelSuccess(string channelName, uint uid, int elapsed)
    {
        print("Joined with uid " + uid);
        myId = uid;
        playerOne.Set(0);
    }

    private void OnUserJoined(uint uid, int elapsed)
    {
        string userJoinedMessage = string.Format("onUserJoined callback uid {0} with elapsed {1}", uid, elapsed);
        print(userJoinedMessage);

        playerTwo.Set(uid);
    }

    private void OnUserLeave(uint uid, USER_OFFLINE_REASON reason)
    {
        string userLeaveMessage = string.Format("onUserOffline callback uid {0} with reason {1}", uid, reason);
        print(userLeaveMessage);

        playerTwo.Clear();
    }

    private void OnLeaveChannel(RtcStats stats)
    {
        playerTwo.Clear();
    }

    private void OnApplicationQuit()
    {
        UnloadEngine();
    }

我在代码中错过了什么吗?

编辑

我怀疑这是Agora API错误,其中在运行时中更改UID时视频界面将不会继续流传输视频。这解释了当同一用户离开并重新加入时,他每次重新加入都会获得不同的uid。视频界面将需要将UID设置为另一个数字,这会导致视频界面停止流式传输。

解决方案>>]

我使用统一实例化解决了这一问题,即在连接到通道时实时实例化视频表面,并在离开通道时销毁视频表面游戏对象。

我尝试使用Unity制作视频流应用程序,并且我已经成功连接了两个用户,并且能够进行视频聊天和共享屏幕。现在的问题是当另一个/第二个用户按请假...

c# visual-studio unity3d video-streaming agora.io
1个回答
0
投票

首先,好名声! ;)

© www.soinside.com 2019 - 2024. All rights reserved.