I have been trying to make a VR Video Player app for Google Cardboard on Android, where video can either be streamed or downloaded. The video works fine in the editor but the does not work in my phone. I am using Unity 5.6.1f1 on Windows 10, the phone is a Moto G4 plus running on Noughat.
Here are the scripts used to stream or download video
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GazeButton : MonoBehaviour {
public static bool toStream;
//private bool buttonPress;
public Image streamImg;
public Image downImg;
public Slider progress;
public Text txt;
//public WWW url;
//public GvrVideoPlayerTexture
private PlayVideo thePlayVideo;
public Camera theCamera;
// Use this for initialization
void Start () {
if (theCamera == null)
theCamera = GameObject.Find ("Main Camera").GetComponent<Camera> ();
if(streamImg == null)
streamImg = GameObject.Find ("StreamImage").GetComponent<Image>();
if(downImg == null)
downImg = GameObject.Find ("DownImage").GetComponent<Image>();
streamImg.color = Color.green;
downImg.color = Color.red;
if (progress == null)
progress = GameObject.Find ("ProgressSlider").GetComponent<Slider> ();
progress.value = 0;
progress.gameObject.SetActive (false);
if (txt == null)
txt = GameObject.Find ("GuideText").GetComponent<Text>();
thePlayVideo = FindObjectOfType<PlayVideo> ();
}
// Update is called once per frame
void Update () {
if (progress.IsActive()) {
progress.value += 1;
if (progress.value >= progress.maxValue /*&& buttonPress*/) {
if (toStream) {
streamImg.color = Color.gray;
streamImg.gameObject.SetActive (false);
downImg.gameObject.SetActive (false);
progress.gameObject.SetActive (false);
txt.gameObject.SetActive (false);
//FlipCameraView ();
thePlayVideo.Stream ();
} else {
downImg.color = Color.gray;
streamImg.gameObject.SetActive (false);
downImg.gameObject.SetActive (false);
progress.gameObject.SetActive (false);
txt.gameObject.SetActive (false);
//FlipCameraView ();
thePlayVideo.Download ();
}
}
}
}
public void StreamButtonDown(){
streamImg.color = Color.blue;
toStream = true;
//buttonPress = true;
progress.gameObject.SetActive (true);
progress.value = 0;
}
public void DownButtonDown(){
downImg.color = Color.blue;
toStream = false;
//buttonPress = true;
progress.gameObject.SetActive (true);
progress.value = 0;
}
public void StreamButtonUp(){
streamImg.color = Color.green;
//buttonPress = false;
progress.gameObject.SetActive (false);
}
public void DownButtonUp(){
downImg.color = Color.red;
//buttonPress = false;
progress.gameObject.SetActive (false);
}
public bool GetCondition(){
return toStream;
}
}
And this is used to actually stream the video :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class PlayVideo : MonoBehaviour {
//public GameObject theSphere;
private VideoPlayer theVideoPlayer;
//private VideoSource theVideoSource;
private AudioSource theAudioSource;
public GazeButton theGazeButton;
// Use this for initialization
void Start () {
/*if (theSphere == null)
theSphere = GameObject.Find ("Sphere");*/
theGazeButton = GetComponent<GazeButton> ();
}
// Update is called once per frame
void Update () {
if (theVideoPlayer != null) {
if (/*(!theGazeButton.GetCondition ()) &&*/ theVideoPlayer.isPrepared) {
theVideoPlayer.Play ();
theAudioSource.Play ();
}
}
}
public void RealStart(){
theVideoPlayer = gameObject.AddComponent<VideoPlayer> ();
//theVideoSource = gameObject.AddComponent<VideoSource> ();
theAudioSource = gameObject.AddComponent<AudioSource> ();
theVideoPlayer.source = VideoSource.Url;
theVideoPlayer.url = "https://<SOME LINK>.mp4";
//theSphere.AddComponent<VideoPlayer>(theVideoPlayer);
theVideoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
theVideoPlayer.EnableAudioTrack (0, true);
theVideoPlayer.SetTargetAudioSource (0, theAudioSource);
}
public void Stream(){
RealStart ();
theVideoPlayer.playOnAwake = true;
theVideoPlayer.Play ();
theAudioSource.Play ();
}
public void Download(){
RealStart ();
theVideoPlayer.playOnAwake = false;
theVideoPlayer.Prepare ();
}
}
I can't for the life of mine, understand why the video runs perfectly in the Editor and not on the phone. Please Help