Unity Screen share 的例子在android 平台无法共享mic的声音 无法对话

问题描述
本人希望做一个移动和pc 对讲系统. 功能包含

  1. android 端通过 agora unity sdk 共享屏幕
  2. pc端可以看到手机的屏幕
  3. 双方可以语音通话

按照以下代码测试发现

  1. android 端可以听到pc的 mic声音. 但是pc 听不到 android 的mic 声音
  2. 如果将android端程序 在pc unity 中直接运行 那就可以发出mic的声音.
    有什么办法解决?

https://docs.agora.io/en/Interactive%20Broadcast/screensharing_unity?platform=Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using agora_gaming_rtc;
using UnityEngine.UI;
using System.Globalization;
using System.Runtime.InteropServices;
using System;

public class ShareScreen : MonoBehaviour
{
Texture2D mTexture;
Rect mRect;
[SerializeField]
private string appId = “Your_AppID”;
[SerializeField]
private string channelName = “agora”;
public IRtcEngine mRtcEngine;
int i = 100;

void Start()
{
Debug.Log(“ScreenShare Activated”);
mRtcEngine = IRtcEngine.GetEngine(appId);
// Sets the output log level of the SDK.
mRtcEngine.SetLogFilter(LOG_FILTER.DEBUG | LOG_FILTER.INFO | LOG_FILTER.WARNING | LOG_FILTER.ERROR | LOG_FILTER.CRITICAL);
// Enables the video module.
mRtcEngine.EnableVideo();
// Enables the video observer.
mRtcEngine.EnableVideoObserver();
// Configures the external video source.
mRtcEngine.SetExternalVideoSource(true, false);
// Joins a channel.
mRtcEngine.JoinChannel(channelName, null, 0);
// Creates a rectangular region of the screen.
mRect = new Rect(0, 0, Screen.width, Screen.height);
// Creates a texture of the rectangle you create.
mTexture = new Texture2D((int)mRect.width, (int)mRect.height, TextureFormat.BGRA32, false);
}

void Update()
{
StartCoroutine(shareScreen());
}

// Starts to share the screen.
IEnumerator shareScreen()
{
yield return new WaitForEndOfFrame();
// Reads the pixels of the rectangle you create.
mTexture.ReadPixels(mRect, 0, 0);
// Applies the pixels read from the rectangle to the texture.
mTexture.Apply();
// Gets the raw texture data and apply it to an array of bytes.
byte[] bytes = mTexture.GetRawTextureData();
// Gives enough space for the bytes array.
int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
// Checks whether the IRtcEngine instance exists.
IRtcEngine rtc = IRtcEngine.QueryEngine();
if (rtc != null)
{
// Creates a new external video frame.
ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
// Sets the buffer type of the video frame.
externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
// Sets the format of the video pixel.
externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
// Applies the raw data.
externalVideoFrame.buffer = bytes;
// Sets the width (pixel) of the video frame.
externalVideoFrame.stride = (int)mRect.width;
// Sets the height (pixel) of the video frame.
externalVideoFrame.height = (int)mRect.height;
// Removes pixels from the sides of the frame
externalVideoFrame.cropLeft = 10;
externalVideoFrame.cropTop = 10;
externalVideoFrame.cropRight = 10;
externalVideoFrame.cropBottom = 10;
// Rotates the video frame (0, 90, 180, or 270)
externalVideoFrame.rotation = 180;
// Increments i with the video timestamp.
externalVideoFrame.timestamp = i++;
// Pushes the external video frame with the frame you create.
int a = rtc.PushVideoFrame(externalVideoFrame);
}
}
}

只是 手机mic权限的问题 …