Unity3d movietexture video playback

Source: Internet
Author: User

Reference Source

Two video playback methods have been provided for reference, where movietexture is used.

Install QuickTime player first.

Unitysupported video formats include .mov?.mpg=.mpeg=.mp4,. Avi, And. ASF.

After QuickTime is installed, pull the video into assets. It will be displayed after a while. If it is white, the quick time is not installed successfully, or restart and try again.

Create a movie playscript,

Using unityengine; using system. collections; public class test: monobehaviour {// movie texture public movietexture movtexture; void start () {// set the playback mode of the movie texture to cycle movtexture. loop = true;} void ongui () {// draw the movie texture GUI. drawtexture (New rect (0, 0, screen. width, screen. height), movtexture, scalemode. stretchtofill); If (guilayout. button ("play/continue") {// play/continue to play the video if (! Movtexture. isplaying) {movtexture. play () ;}} if (guilayout. button ("pause playback") {// pause playback movtexture. pause ();} If (guilayout. button ("Stop playing") {// stop playing movtexture. stop ();}}}

This statement declares public movietexture movtexture; and then binds the script to main camera.

Select the bound video. Now you can play the video on PC.

Mobile PlatformTested

The above method cannot play videos on iOS and Android devices. We need to use another method to play videos on mobile devices.Play videos on the platform

using UnityEngine;using System.Collections;public class Test : MonoBehaviour {    void OnGUI()    {        if (GUI.Button (new Rect (20,10,200,50), "PLAY ControlMode.CancelOnTouch"))         {               Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput);        }        if (GUI.Button (new Rect (20,90,200,25), "PLAY ControlMode.Full"))         {               Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Full);        }        if (GUI.Button (new Rect (20,170,200,25), "PLAY ControlMode.Hidden"))         {                Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Hidden);            }        if (GUI.Button (new Rect (20,250,200,25), "PLAY ControlMode.Minimal"))         {               Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Minimal);        }    }}

1. When a video is played, the touch screen video is disabled.

2. the IOS advanced control is displayed during video playback to control the full screen of video pause.

3. The video cannot be stopped. It is automatically disabled once it is played.

4. the IOS advanced control is displayed during video playback to control the playback progress.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.