将视频流到Google VR纸板Unity中的Android设备



我一直在尝试为Android上的Google Cardboard制作一个VR Video Player应用程序,可以在其中流式传输或下载视频。该视频在编辑器中正常工作,但我的手机不起作用。我在Windows 10上使用Unity 5.6.1f1,手机是Moto G4 Plus在Noughat上运行的。

这是用于流式传输或下载视频

的脚本
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;
}
}

这实际上用于流式传输视频:

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 ();
}
}

我不能为我的一生而言,请理解为什么视频在编辑器中完美地运行而不是在电话中运行。请帮助

使用现代统一编辑器(至少2017.4 lts(,并安装最新的Google VR SDK进行Unity。在那里,查看 videodemo.scene 文件,以查看Google Cardboard中的视频。

最新更新