将视频内容播放到目标上。
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 | Whether you can change the playback speed. (Read Only) |
| canSetSkipOnDrop | 是否可以控制跳帧以保持同步。(只读) |
| canSetTime | Whether you can change the current time using the time or timeFrames property. (Read Only) |
| canSetTimeUpdateMode | Whether you can change the time source followed by the VideoPlayer. (Read Only) |
| 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 | 将绘制视频内容的位置。 |