【问题标题】:Streaming video to Android Device in Google VR Cardboard in Unity在 Unity 的 Google VR Cardboard 中将视频流式传输到 Android 设备
【发布时间】:2017-06-07 19:53:23
【问题描述】:

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

这里是用于流式传输或下载视频的脚本

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

}
}

我一辈子都无法理解为什么视频在编辑器中完美运行,而不是在手机上运行。请帮忙

【问题讨论】:

  • 只需使用此script 创建新场景并播放视频。阅读上面写着“从 URL 播放视频” 的地方,然后执行此操作。在编辑器上试用,然后在 Android 设备上试用。如果它在 Android 设备上不起作用,那么这是一个错误。让我知道结果
  • 同样,它在编辑器中有效,但在设备上无效。
  • 我知道。就这样做,然后告诉我结果。确保使用该链接中的视频网址。
  • 不,我的意思是我按照你说的做了。结果在编辑器中有效,但在设备上无效。我现在已经检查了 2-3 台设备。
  • 另外,我确实看过 Luzan 的教程,并尝试制作它以便在创建上述脚本时流式传输视频。

标签: android unity3d virtual-reality


【解决方案1】:

使用现代 Unity 编辑器(至少 2017.4 LTS)并安装最新的 Google VR SDK for Unity。在那里,查看 VideoDemo.scene 文件以在 Unity 上的 Google Cardboard 中查看视频。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2012-07-24
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多