ReplayKit 仅适用于某些运行 iOS 9.0 或更高版本的 iPhone、iPad 和 iPod Touch 设备。
ReplayKit 允许通过麦克风录制游戏音频和视频以及用户解说, 以及通过摄像机录制用户视频。使用 StartRecording() 函数开始录制,使用 StopRecording() 停止录制。可以 使用 Preview() 函数预览录制。此函数可启动一个独立的视频查看器。除 本地录制外,还可通过 StartBroadcasting() 广播录制内容。此外还有 暂停、继续和停止广播的函数。
using System; using UnityEngine; #if PLATFORM_IOS using UnityEngine.iOS; using UnityEngine.Apple.ReplayKit;
public class Replay : MonoBehaviour { public bool enableMicrophone = false; public bool enableCamera = false;
string lastError = ""; void OnGUI() { if (!ReplayKit.APIAvailable) { return; } var recording = ReplayKit.isRecording; string caption = recording ? "Stop Recording" : "Start Recording"; if (GUI.Button(new Rect(10, 10, 500, 200), caption)) { try { recording = !recording; if (recording) { ReplayKit.StartRecording(enableMicrophone, enableCamera); } else { ReplayKit.StopRecording(); } } catch (Exception e) { lastError = e.ToString(); } }
GUI.Label(new Rect(10, 220, 500, 50), "Last error: " + ReplayKit.lastError); GUI.Label(new Rect(10, 280, 500, 50), "Last exception: " + lastError);
if (ReplayKit.recordingAvailable) { if (GUI.Button(new Rect(10, 350, 500, 200), "Preview")) { ReplayKit.Preview(); } if (GUI.Button(new Rect(10, 560, 500, 200), "Discard")) { ReplayKit.Discard(); } } }
void Update() { // If the camera is enabled, show the recorded video overlaying the game. if (ReplayKit.isRecording && enableCamera) ReplayKit.ShowCameraPreviewAt(10, 350, 200, 200); else ReplayKit.HideCameraPreview(); } } #endif
APIAvailable | 用于表示 ReplayKit API 是否可用的布尔值(true 表示可用)。(只读) |
broadcastingAPIAvailable | 表示 ReplayKit broadcasting API 是否可用的布尔值(true 表示可用)(只读)。 请在执行 ReplayKit broadcasting API 调用之前查看此属性的值。在 iOS 10 之前的 iOS 版本中,此属性的值为 false。 |
broadcastURL | 包含用于将用户重定向到正在进行或已完成广播的 URL 的字符串属性(只读)。 |
cameraEnabled | 摄像机已启用状态。如果启用了摄像机,则为 true;否则为 false。 |
isBroadcasting | 用于表示广播是否正在进行的布尔值属性(只读)。 |
isBroadcastingPaused | 用于表示广播当前是否已暂停的布尔值属性(只读)。 |
isPreviewControllerActive | 表示 ReplayKit 当前是否正在显示预览控制器的布尔值。(只读) |
isRecording | 用于表示 ReplayKit 是否正在录制的布尔值(true 表示正在录制)。(只读) |
lastError | ReplayKit 发生的上一个错误的字符串值:“Failed to get Screen Recorder”或“No recording available”。(只读) |
microphoneEnabled | 麦克风已启用状态。如果启用了麦克风,则为 true;否则为 false。 |
recordingAvailable | 用于表示新录制是否可用于预览的布尔值(true 表示可用)。(只读) |
Discard | 放弃当前录制。 |
HideCameraPreview | 隐藏摄像机预览视图。 |
PauseBroadcasting | 暂停当前广播。 将暂停当前正在进行的广播。如果没有在广播,则不执行任何操作。 |
Preview | 预览当前录制 |
ResumeBroadcasting | 继续当前广播。 将继续当前正在进行的广播。如果没有在广播,则不执行任何操作。 |
ShowCameraPreviewAt | 显示坐标 posX 和 posY 上的摄像机预览。预览大小为宽度乘以高度。 |
StartBroadcasting | 启动新广播 调用 StartBroadcast 后,用户会看到广播提供程序选择屏幕和广播设置屏幕。完成后,广播将会开始,回调将被调用。 如果出现错误,回调也将被调用。 |
StartRecording | 启动新录制。 |
StopBroadcasting | 停止当前广播。 将终止当前正在进行的广播。如果没有广播正在进行中,则不执行任何操作。 |
StopRecording | 停止当前录制。 |
BroadcastStatusCallback | 广播启动完成时调用的函数。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.