Last active
April 2, 2017 18:36
-
-
Save joduplessis/82e742e46246dfd821584d8406ad04b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Very simple demo showing how to play videos | |
* using RawTexture and Unity 5.x UI | |
* | |
* Just a note - this is PC/OSX specific | |
*/ | |
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System; | |
using DG.Tweening; | |
public class Video : MonoBehaviour { | |
MovieTexture movieTexture; | |
RawImage videoTexture; | |
AudioSource audio; | |
void Update () { | |
} | |
void Start() { | |
// Load video | |
StartCoroutine(loadVideo()); | |
} | |
IEnumerator loadVideo () { | |
string url = "path/to/file"; | |
// Make the request over www | |
WWW wwwRequest = new WWW (url); | |
yield return wwwRequest; | |
// Assign the raw image the movie texture | |
// yes this throws an error - it is a bug in Unity | |
// https://issuetracker.unity3d.com/issues/movietexture-fmod-error-when-trying-to-play-video-using-www-class | |
movieTexture = (MovieTexture) wwwRequest.movie; | |
videoTexture.texture = movieTexture; | |
// Play the audio attached to this object | |
GetComponent<AudioSource> ().clip = movieTexture.audioClip; | |
// Start the video | |
// You could Stop, Pause, Play here | |
movieTexture.Play (); | |
// Lower the volume using the DOTTween libary | |
audio.DOFade (0.1f, 3.0f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment