0

I would like to download a video from a URL and play it in the unity / Daydream app that I'm making for Android.

I'm not really sure where to save the downloaded video so the App can use it.

I can download the video to Android Application.persistentDataPath but it does not seem to work when I try and download the video to the StreamingAssets path.

I was under the impression that I need to read the video files from the StreamingAssets path?

thanks for any help :)

4

1 回答 1

1

通过对 Daydream Unity SDK 中的 Daydream 视频示例稍作修改,我成功地完成了这项工作。在 SwitchVideo.cs 的“ShowSample”函数中,我替换了加载新视频的代码。

我正在做的是:

  1. 将视频下载到 Application.persistentDataPath 下。
  2. 附加file://到文件路径。我相信这是必要的,因为您还可以使用 jar 访问内置的文件jar:,这些文件需要解压缩。你下载的那个没有。
  3. 设置GvrVideoPlayerTexture.videoURL到这个路径。
  4. 在这种情况下,type设置为other,并且内容 ID 和提供者 ID 为空。
  5. 打电话ReInitializeVideo

      var www = new WWW("https://archive.org/download/Pbtestfilemp4videotestmp4/video_test_512kb.mp4");
      var path = Application.persistentDataPath + "/a.mp4";
    
      while (!www.isDone) {
        print(www.progress);
      }
      File.WriteAllBytes(path, www.bytes);
    
      var video = videoSamples[i].GetComponentInChildren<GvrVideoPlayerTexture>();
      video.videoURL = "file://" + path;
      video.ReInitializeVideo();
    

请注意,您也可以流式传输视频。如果您设置videoURL为 http 路径,它应该可以工作,但我假设您想要一些可以保存视频以供离线使用的东西。

于 2017-03-13T21:43:58.297 回答