视频播放--MovieTexture和VideoPlayer


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 initialization
	void Start () {     
        GetComponent<RawImage>().texture = movie;
        audio = GetComponent<AudioSource>();
        movie.Play();
        audio.Play();
	}
	
	// Update is called once per frame
	void 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 the Texture 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 of Video 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 earlier Movie Textures feature.

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

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

CameraFarPlane Draw video content behind a camera's scene.
CameraNearPlane Draw video content in front of a camera's scene.
RenderTexture Draw video content into a RenderTexture.
MaterialOverride Draw the video content into a user-specified property of the current GameObject's material.
APIOnly Don'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点击打开链接


猜你喜欢

转载自blog.csdn.net/u012221316/article/details/75195954
今日推荐