Created
July 19, 2018 23:17
-
-
Save tsonglew/56fdd503fae870f8a27d1ec408a2e552 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Video; | |
using UnityEngine.UI; | |
public class testScript : MonoBehaviour { | |
public RawImage image; | |
private VideoPlayer videoPlayer; | |
private VideoSource videoSource; | |
private AudioSource audioSource; | |
// Use this for initialization | |
void Start () { | |
Application.runInBackground = true; | |
StartCoroutine (playVideo()); | |
} | |
IEnumerator playVideo() { | |
videoPlayer = gameObject.AddComponent<VideoPlayer> (); | |
audioSource = gameObject.AddComponent<AudioSource> (); | |
videoPlayer.playOnAwake = false; | |
audioSource.playOnAwake = false; | |
audioSource.Pause (); | |
videoPlayer.source = VideoSource.Url; | |
videoPlayer.url = "http://oonvtay51.bkt.clouddn.com/GongxiangVideo.mp4"; | |
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; | |
videoPlayer.EnableAudioTrack (0, true); | |
videoPlayer.SetTargetAudioSource (0, audioSource); | |
videoPlayer.Prepare (); | |
WaitForSeconds waitTime = new WaitForSeconds (1); | |
while (!videoPlayer.isPrepared) { | |
Debug.Log ("Preparing video"); | |
yield return waitTime; | |
break; | |
} | |
Debug.Log ("Done Preparing Video"); | |
image.texture = videoPlayer.texture; | |
videoPlayer.Play (); | |
Debug.Log ("Playing Video"); | |
while (videoPlayer.isPlaying) { | |
Debug.LogWarning ("Video Time: " + Mathf.FloorToInt ((float)videoPlayer.time)); | |
yield return null; | |
} | |
Debug.Log ("Done Playing Video"); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment