Appearance
应用内使用投录屏
TIP
如非必要,不建议单独调用投录屏接口,建议直接使用系统的投录屏功能,详细使用参考眼镜系统说明文档。 如必须应用内调用投录屏接口,可能会有部分适配问题,如后处理或部分特效等,或不同系统版本兼容问题。
TIP
应用内独立调用投录屏功能,仅支持应用内投录屏,不支持跨场景投录屏
应用内调用录屏功能
环境配置
无需特别设置
当前版本不支持录制音频
代码使用
参考 OSEventSystem.cs 中调用 RecordingManager 的代码。
或者按照如下代码书写调用
json
public void OnRecordButtonPressed()
{
if (!isRecording)
{
if (RecordingManager.Instance != null)
{
Destroy(RecordingManager.Instance.gameObject);
}
StartCoroutine(tryStartRecording());
isRecording = true;
}
else
{
isRecording = false;
if (RecordingManager.Instance != null && RecordingManager.Instance.isRecording)
{
RecordingManager.Instance.HandleRecordingClose();
}
}
}
private bool isRecording = false;
private IEnumerator tryStartRecording()
{
yield return new WaitForSeconds(2);
GameObject recordingManagerObj = Instantiate(ResourcesManager.Load<GameObject>("RecordingManager"));
GameObject cameraRigObj = HMDPoseTracker.Instance.gameObject;
if (XRMan.Exist)
{
recordingManagerObj.transform.position = XRMan.offset_SpatialComputing.GetColumn(3);
recordingManagerObj.transform.rotation = XRMan.offset_SpatialComputing.rotation;
}
else
{
if (cameraRigObj != null && cameraRigObj.transform.parent != null)
{
recordingManagerObj.transform.parent = cameraRigObj.transform.parent;
recordingManagerObj.transform.localPosition = Vector3.zero;
recordingManagerObj.transform.localRotation = Quaternion.identity;
}
}
if (RecordingManager.Instance != null)
RecordingManager.Instance.HandleRecordingOpen();
}
应用内调用投屏功能
环境配置
在场景中鼠标右击 XR Abilities->Additinal->Miracast->Enable,导入依赖项
按步骤导入依赖的资源。
代码使用
同样参考 OSEventSystem.cs 中调用 MiracastManager 的代码。
或者按照如下代码书写调用
json
private bool isMiracasting = false;
public void **OnMiracstButtonPressed**()
{
if (!isMiracasting)
{
if (MiracastManager.Instance != null)
{
DestroyImmediate(MiracastManager.Instance.gameObject);
}
StartCoroutine(tryStartMiracast());
isMiracasting = true;
}
else
{
isMiracasting = false;
if (MiracastManager.Instance != null && MiracastManager.Instance.isMiracasting)
{
MiracastManager.Instance.Stop();
}
}
}
private IEnumerator tryStartMiracast()
{
if (MiracastManager.Instance != null)
{
MiracastManager.Instance.Stop();
}
yield return new WaitForSeconds(2);
GameObject miracastManagerObj = Instantiate(ResourcesManager.Load<GameObject>("MiracastManager"));
GameObject cameraRigObj = HMDPoseTracker.Instance.gameObject;
if (XRMan.Exist)
{
miracastManagerObj.transform.position = XRMan.offset_SpatialComputing.GetColumn(3);
miracastManagerObj.transform.rotation = XRMan.offset_SpatialComputing.rotation;
}
else
{
if (cameraRigObj != null && cameraRigObj.transform.parent != null)
{
miracastManagerObj.transform.parent = cameraRigObj.transform.parent;
miracastManagerObj.transform.localPosition = Vector3.zero;
miracastManagerObj.transform.localRotation = Quaternion.identity;
}
}
if (MiracastManager.Instance != null)
{
Debug.Log("TryStartServer: 2 ip="+ miracstIP);
MiracastManager.Instance.Run(miracstIP);
Utilities.Android.SendIntent("ToSystem", "com.ezxr.glass.systemui", "MiracastStatus", "Started");
}
}