简体   繁体   中英

Unity + Android + Daydream, download video file and play in app

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 :)

I got this to work successfully with a little modification to the Daydream video sample inside the Daydream Unity SDK. Inside the "ShowSample" function in SwitchVideo.cs, I replaced the code which loads a new video.

What I'm doing is:

  1. Download video to something under Application.persistentDataPath.
  2. Prepend file:// to the file path. I believe this is necessary because you can also access files built into the jar using jar: and these would need to be unzipped. The one you download does not.
  3. Set GvrVideoPlayerTexture.videoURL to this path.
  4. In this case, type is set to other , and the content ID and provider ID are left empty.
  5. Call 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(); 

Note that you can stream videos too. If you set videoURL to an http path, it should work, but I'm assuming you want something that can save the videos for offline use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM