0

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

Lord_Regent
  • 43
  • 1
  • 7
  • Just create new scene and play video with this [script](https://stackoverflow.com/a/41154599/3785314). Read where it says **"Play Video From URL"** and do that. Try it on the Editor then on the Android device. If it does not work on the Android device then that is a bug. Let me know the outcome – Programmer Jun 07 '17 at 20:19
  • Again, it works in the editor but not on the device. – Lord_Regent Jun 07 '17 at 21:31
  • I know. Just do that and tell me the outcome. Make sure to use the video url from that link. – Programmer Jun 07 '17 at 21:32
  • No, I meant that I did what you said. The resultant works in the editor but not on the device. And I've checked across 2-3 devices now. – Lord_Regent Jun 07 '17 at 21:36
  • Also, I did see Luzan's tutorial and tried to make so it could stream the videos, in creating the aforementioned scripts. – Lord_Regent Jun 07 '17 at 21:39
  • That's what I wanted to make sure of. This is a bug. Go to *Help* --> *Report a Bug...* – Programmer Jun 07 '17 at 21:58

1 Answers1

0

Use a modern Unity editor (at least 2017.4 LTS) and install the latest Google VR SDK for Unity. There, look at the VideoDemo.scene file to see video in Google Cardboard on Unity.

DoctorPangloss
  • 2,994
  • 1
  • 18
  • 22