Version: 2021.3

VideoPlayer

class in UnityEngine.Video

/

继承自:Behaviour

切换到手册

描述

将视频内容播放到目标上。

Content can be either a VideoClip imported asset or a URL such as file:// or http://. Video content will be projected onto one of the supported targets, such as camera background or RenderTexture. If the video content includes transparency, this transparency will be present in the target, allowing objects behind the video target to be visible. When the data VideoPlayer.source is set to URL, the audio and video description of what is being played will only be initialized once the VideoPlayer preparation is completed. You can test this with VideoPlayer.isPrepared.

以下部分演示了 VideoPlayer 的一些功能:

// Examples of VideoPlayer function

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // Will attach a VideoPlayer to the main camera. GameObject camera = GameObject.Find("Main Camera");

// VideoPlayer automatically targets the camera backplane when it is added // to a camera object, no need to change videoPlayer.targetCamera. var videoPlayer = camera.AddComponent<UnityEngine.Video.VideoPlayer>();

// Play on awake defaults to true. Set it to false to avoid the url set // below to auto-start playback since we're in Start(). videoPlayer.playOnAwake = false;

// By default, VideoPlayers added to a camera will use the far plane. // Let's target the near plane instead. videoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.CameraNearPlane;

// This will cause our Scene to be visible through the video being played. videoPlayer.targetCameraAlpha = 0.5F;

// Set the video to play. URL supports local absolute or relative paths. // Here, using absolute. videoPlayer.url = "/Users/graham/movie.mov";

// Skip the first 100 frames. videoPlayer.frame = 100;

// Restart from beginning when done. videoPlayer.isLooping = true;

// Each time we reach the end, we slow down the playback by a factor of 10. videoPlayer.loopPointReached += EndReached;

// Start playback. This means the VideoPlayer may have to prepare (reserve // resources, pre-load a few frames, etc.). To better control the delays // associated with this preparation one can use videoPlayer.Prepare() along with // its prepareCompleted event. videoPlayer.Play(); }

void EndReached(UnityEngine.Video.VideoPlayer vp) { vp.playbackSpeed = vp.playbackSpeed / 10.0F; } }

静态变量

controlledAudioTrackMaxCount可以控制的最大音频轨道数量。(只读)

变量

aspectRatio定义如何拉伸视频内容以填充目标区域。
audioOutputMode嵌入在视频中的音频的目标。
audioTrackCount在当前配置的数据源中找到的音频轨道数量。(只读)
canSetDirectAudioVolume当前平台和视频格式是否支持直接输出音量控制。(只读)
canSetPlaybackSpeed播放速度是否可以更改。(只读)
canSetSkipOnDrop是否可以控制跳帧以保持同步。(只读)
canSetTime是否可以使用 time 或 timeFrames 属性更改当前时间。(只读)
canSetTimeSource是否可以更改 VideoPlayer 遵循的时间源。(只读)
canStep如果 VideoPlayer 可以使视频内容前进,则返回 /true/。(只读)
clip VideoPlayer 正在播放的剪辑。
clockTime VideoPlayer 采样时遵循的时钟时间。此时钟时间以秒为单位。(只读)
controlledAudioTrackCount此 VideoPlayer 将控制的音频轨道数量。
externalReferenceTime VideoPlayer 用于纠正其偏差的外部时钟的参考时间。
frame VideoPlayer.texture 中当前可用帧的帧索引。
frameCount当前视频内容中的帧数。(只读)
frameRate剪辑或 URL 的帧率(以帧/秒为单位)。(只读)
height VideoClip 或 URL 中的图像的高度(以像素为单位)。(只读)
isLooping确定当 VideoPlayer 到达剪辑的结尾时是否从头开始播放。
isPaused是否已暂停播放。(只读)
isPlaying是否正在播放内容。(只读)
isPrepared VideoPlayer 是否已完成待播放内容的准备工作。(只读)
length VideoClip 或 URL 的长度(以秒为单位)。(只读)
pixelAspectRatioDenominator VideoClip 或 URL 的像素宽高比(分子:分母)的分母。(只读)
pixelAspectRatioNumerator VideoClip 或 URL 的像素宽高比(分子:分母)的分子。(只读)
playbackSpeed基本播放速率的增加倍数。
playOnAwake内容是否会在组件被唤醒后立即开始播放。
renderMode将绘制视频内容的位置。
sendFrameReadyEvents启用 frameReady 事件。
skipOnDrop是否允许 VideoPlayer 跳帧以追上当前时间。
source VideoPlayer 用于播放的源。
targetCamera当 VideoPlayer.renderMode 设置为 VideoRenderMode.CameraFarPlane 或 VideoRenderMode.CameraNearPlane 时,要在其中绘制资源的 Camera 组件。
targetCamera3DLayout源视频媒体中包含的 3D 内容的类型。
targetCameraAlpha目标摄像机平面视频的整体透明度级别。
targetMaterialProperty在 VideoPlayer.renderMode 设置为 Video.VideoTarget.MaterialOverride 时被设为目标的 Material 纹理属性。
targetMaterialRenderer在 VideoPlayer.renderMode 设置为 Video.VideoTarget.MaterialOverride 时被设为目标的 Renderer
targetTexture当 VideoPlayer.renderMode 设置为 Video.VideoTarget.RenderTexture 时,要在其中绘制资源的 RenderTexture。
texture放置视频内容的内部纹理。(只读)
time VideoPlayer.texture 中当前可用帧的准备时间。
timeReference VideoPlayer 对其进行观测以发现和纠正偏差的时钟。
timeSource[尚未实现] VideoPlayer 用于派生其当前时间的源。
url VideoPlayer 将从中读取内容的文件或 HTTP URL。
waitForFirstFrame确定当 VideoPlayer.playOnAwake 启用时,VideoPlayer 是否会在开始播放之前等待第一帧加载到纹理中。
width VideoClip 或 URL 中的图像的宽度(以像素为单位)。(只读)

公共函数

EnableAudioTrack启用/禁用音频轨道解码。仅在 VideoPlayer 当前未播放时有效。
GetAudioChannelCount指定音频轨道中的音频声道数。
GetAudioLanguageCode返回指定轨道的语言代码(如果有)。
GetAudioSampleRate获取音频轨道的采样率(以赫兹为单位)。
GetDirectAudioMute获取指定轨道的直接输出音频静音状态。
GetDirectAudioVolume返回指定轨道的直接输出音量。
GetTargetAudioSource获取当 VideoPlayer.audioOutputMode 设置为 VideoAudioOutputMode.AudioSource 时将接收指定轨道的音频样本的 AudioSource。
IsAudioTrackEnabled是否启用了对指定音频轨道的解码。请参阅 VideoPlayer.EnableAudioTrack 以了解它与静音的区别。
Pause暂停播放并保持当前时间不变。
Play开始播放。
Prepare启动播放引擎准备。
SetDirectAudioMute设置指定轨道的直接输出音频静音状态。
SetDirectAudioVolume设置指定轨道的直接输出音频音量。
SetTargetAudioSource设置当使用 VideoPlayer.audioOutputMode 选择此音频目标时将接收指定轨道的音频样本的 AudioSource。
StepForward立即将当前时间向前推进一帧。
Stop停止播放并将当前时间设为 0。

Events

clockResyncOccurred在 VideoPlayer 时钟同步回其 VideoTimeReference 时调用。
errorReceived通过此回调报告 HTTP 连接问题等错误。
frameDropped[尚未实现] 当视频解码器在播放期间没有按照时间源生成帧时调用。
frameReady当新帧准备就绪时调用。
loopPointReached当 VideoPlayer 到达播放内容的结尾时调用。
prepareCompleted当 VideoPlayer 的准备工作完成后调用。
seekCompleted在搜寻操作完成后调用。
started在调用 Play 后立即调用。

委托

ErrorEventHandler包含错误消息的 VideoPlayer 事件的委托类型。
EventHandler VideoPlayer 发出的所有无参数事件的委托类型。
FrameReadyEventHandler带有帧编号的 VideoPlayer 事件的委托类型。
TimeEventHandler带有时间位置的 VideoPlayer 事件的委托类型。

继承的成员

变量

enabled启用的 Behaviour 可更新,禁用的 Behaviour 不可更新。
isActiveAndEnabledReports whether a GameObject and its associated Behaviour is active and enabled.
gameObject此组件附加到的游戏对象。始终将组件附加到游戏对象。
tag此游戏对象的标签。
transform附加到此 GameObject 的 Transform。
hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentReturns the component of type if the GameObject has one attached.
GetComponentInChildrenReturns the Component of type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the Component of type in the GameObject or any of its parents.
GetComponents返回 GameObject 中类型为 type 的所有组件。
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children using depth first search. Works recursively.
GetComponentsInParent返回 GameObject 或其任何父项中类型为 type 的所有组件。
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。