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.