视频播放--MovieTexture和VideoPlayer

来源:互联网 发布:coc五级龙数据 编辑:程序博客网 时间:2024/04/29 18:52


MovieTexture:

Movie Textures are animated Textures that are created from a video file. By placing a video file in your project’sAssets Folder, you can import the video to be used exactly as you would use a regularTexture.

Video files are imported via Apple QuickTime. Supported file types are what your QuickTime installation can play (usually.mov,.mpg,.mpeg, .mp4,.avi,.asf). On Windows, movie importing requires Quicktime to be installed. Download Quicktime fromApple Support Downloads.

电影纹理是从视频文件中创建的动画纹理。将视频文件导入到工程的资源文件夹下,就可以像使用普通纹理一样使用了。需要注意的是,视频文件要通过Apple QuickTime导入,所以电脑上要先安装这个软件。

获取到MovieTexture之后,只需将其设置到某一组件的Texture上,便可通过MovieTexture自带的函数比如Play,Pause,Stop等控制画面的显示,但要想播放声音,还需要在场景中添加AudioSource,像播放普通音频一样进行播放。

下例是在RawImage上播放视频,同时播放声音的示例:

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class VideoPlayTest : MonoBehaviour {    public MovieTexture movie;    private AudioSource audio;// Use this for initializationvoid Start () {             GetComponent<RawImage>().texture = movie;        audio = GetComponent<AudioSource>();        movie.Play();        audio.Play();}// Update is called once per framevoid Update () {        if (Input.GetKeyDown(KeyCode.Space))        {            if (movie.isPlaying && audio.isPlaying)            {                movie.Pause();                audio.Pause();            }            else            {                movie.Play();                audio.Play();                           }        }        if (Input.GetKeyDown(KeyCode.UpArrow))            audio.volume +=0.1f;        if(Input.GetKeyDown(KeyCode.DownArrow))            audio.volume -= 0.1f;          }}

VideoPlayer

Use Unity’s video system to integrate video into your game. Video footage can add realism, save on rendering complexity, or help you integrate content available externally.

To use video in Unity, import Video Clips and configure them using the Video Player component. The system allows you to feed video footage directly into theTexture parameter of any component that has one. Unity then plays the Video on that Texture at run time.

Unity’s video features include the hardware-accelerated and software decoding ofVideo files, transparency support, multiple audio tracks, and network streaming.

Note: The Video Player component and Video Clip asset, introduced in Unity 5.6, supersede the earlierMovie Textures feature.

特征:Unity的视频功能包括硬件加速和视频文件的软件解码、透明支持、多音轨和网络流。

Video Player是Unity5.6之后新增加的,丰富了Unity播放频的功能,可轻松实现视频播放速度的控制,快进快退,视频透明度控制等。在使用时,将文件导入到工程中后,将其导入格式设置成Video Clip,就可以将其直接设置给Video Player组件的Video Clip属性(前提是Source属性选择为Video Clip方式)。当然,也可以设置Source为URL模式,通过给定具体的视频地址实现视频的播放。

CameraFarPlaneDraw video content behind a camera's scene.CameraNearPlaneDraw video content in front of a camera's scene.RenderTextureDraw video content into a RenderTexture.MaterialOverrideDraw the video content into a user-specified property of the current GameObject's material.APIOnlyDon't draw the video content anywhere, but still make it available via the VideoPlayer's texture property in the API.

VideoPlayer的渲染模式有以上几种,选择不同的模式可以将视频渲染到不同的对象上,比如UI控件上、3D物体上,相机近平面和远平面上等。此外,将视频文件拖到不同的GameObject上,系统会自动设置相应的渲染模式。

相关博文:http://blog.csdn.net/dark00800/article/details/70160463点击打开链接


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我长智齿牙龈痛怎么办 出智齿引起牙龈肿痛怎么办 要长智齿牙肉痛怎么办 牙齿肿了有脓包怎么办 牙肉发炎有脓包怎么办 拔智齿伤了神经怎么办 牙下面的肉疼该怎么办 后面牙突然好疼怎么办 拔智齿后的牙洞怎么办 换牙期牙齿长歪怎么办 小孩子牙齿长歪了怎么办 换牙门牙长歪了怎么办 宝宝牙齿长歪了怎么办 小孩的牙齿长歪了怎么办 婴儿门牙长歪了怎么办 牙齿掉了好几颗怎么办 第二磨牙长歪了怎么办 第二乳磨牙坏了怎么办 小孩牙齿都坏了怎么办 第二乳磨牙蛀了怎么办 门牙烂了个洞怎么办 门牙掉了两颗怎么办 牙坏了不能补了怎么办 牙从里面坏了怎么办 百度云容量满了怎么办 mp3连接不上电脑怎么办 深户离职后社保怎么办 依云喷雾过敏了怎么办 阿里云邮箱满了怎么办 苹果手机ic坏了怎么办 王者队友不给力怎么办 协同大作战出bug怎么办 耳朵一个大一个小怎么办 58同城兼职被骗怎么办 我欠了好多钱怎么办 p2p平台跑路了怎么办 别人借钱跑路了怎么办 善心汇崩盘了钱怎么办 日本销签忘记了怎么办 手腕的筋拉伤了怎么办 膝盖韧带拉伤怎么办恢复快