Version: 2021.3
LanguageEnglish
  • C#

ReplayKit

class in UnityEngine.Apple.ReplayKit

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

ReplayKit is only available on certain iPhone, iPad and iPod Touch devices running iOS 9.0 or later.

ReplayKit allows you to record the audio and video of your game, along with user commentary through the microphone and user video through the camera. Start a recording with the StartRecording() function, and stop it with StopRecording(). You can preview the recording with the Preview() function, which launches a separate video viewer. In addition to local recordings, you can broadcast your recordings via StartBroadcasting(). There are also functions to pause, resume, and stop broadcasting.

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

Static Properties

APIAvailableA boolean that indicates whether the ReplayKit API is available (where True means available). (Read Only)
broadcastingAPIAvailableA Boolean that indicates whether ReplayKit broadcasting API is available (true means available) (Read Only). Check the value of this property before making ReplayKit broadcasting API calls. On iOS versions prior to iOS 10, this property will have a value of false.
broadcastURLA string property that contains an URL used to redirect the user to an on-going or completed broadcast (Read Only).
cameraEnabledCamera enabled status. True, if camera enabled; false otherwise.
isBroadcastingBoolean property that indicates whether a broadcast is currently in progress (Read Only).
isBroadcastingPausedBoolean property that indicates whether a broadcast is currently paused (Read Only).
isPreviewControllerActiveA boolean that indicates whether ReplayKit is currently displaying a preview controller. (Read Only)
isRecordingA boolean that indicates whether ReplayKit is making a recording (where True means a recording is in progress). (Read Only)
lastErrorA string value of the last error incurred by the ReplayKit: Either 'Failed to get Screen Recorder' or 'No recording available'. (Read Only)
microphoneEnabledMicrophone enabled status. True, if microphone enabled; false otherwise.
recordingAvailableA boolean value that indicates that a new recording is available for preview (where True means available). (Read Only)

Static Methods

DiscardDiscard the current recording.
HideCameraPreviewHide the camera preview view.
PauseBroadcastingPauses current broadcast. Will pause currently on-going broadcast. If no broadcast is in progress, does nothing.
PreviewPreview the current recording
ResumeBroadcastingResumes current broadcast. Will resume currently on-going broadcast. If no broadcast is in progress, does nothing.
ShowCameraPreviewAtShows camera preview at coordinates posX and posY. The preview is width by height in size.
StartBroadcastingInitiates and starts a new broadcast When StartBroadcast is called, user is presented with a broadcast provider selection screen, and then a broadcast setup screen. Once it is finished, a broadcast will be started, and the callback will be invoked. It will also be invoked in case of any error.
StartRecordingStart a new recording.
StopBroadcastingStops current broadcast. Will terminate currently on-going broadcast. If no broadcast is in progress, does nothing.
StopRecordingStop the current recording.

Delegates

BroadcastStatusCallbackFunction called at the completion of broadcast startup.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961