- Home /
Using VideoPlayer to stream a video from a website
I'm trying to use the new VideoPlayer feature to play a video from a website (my dropbox link). I can't seem to figure out the right url format to get the video to play. I've just been copying the video link from dropbox and putting it in as the url but that doesn't seem to work. I've also tried videos from other websites and couldn't get those to work either. I tried actually bringing the video file into unity and playing it directly instead of through the url and it works fine. Here's the code I have: (I press a button in the scene to begin playing the video)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class Test : MonoBehaviour {
Camera cam;
UnityEngine.Video.VideoPlayer vid;
AudioSource aud;
void Start () {
cam = Camera.main;
aud = cam.GetComponent<AudioSource> ();
vid = cam.GetComponent<UnityEngine.Video.VideoPlayer> ();
vid.renderMode = UnityEngine.Video.VideoRenderMode.CameraNearPlane;
vid.url = "https://www.dropbox.com/s/cquqv1zb31b04p4/Vid-648155715.ogv?dl=0";
vid.audioOutputMode = VideoAudioOutputMode.AudioSource;
vid.EnableAudioTrack (0, true);
vid.SetTargetAudioSource (0, aud);
vid.Prepare ();
}
void Update () {
Debug.Log (vid.isPlaying);
}
public void PlayMovie(){
vid.Play ();
}
}
Does the video have to be in a certain format for unity to play it? And how can I fix this so I can play the video through the url? Or would there be a better way to handle playing these videos without streaming them from a website? (I intend to have hundreds of videos so I didn't think having them all locally in unity would be very efficient)
Audio is not playing for that video? What's the issue ?
Answer by Sir-Gatlin · Jul 03, 2017 at 06:07 PM
normally you would host the videos on a server of your own. Dropbox does work but it takes a little bit of tweaking, replace your url "https://www.dropbox.com/s/cquqv1zb31b04p4/Vid-648155715.ogv?dl=0"
with "https://dl.dropbox.com/s/cquqv1zb31b04p4/Vid-648155715.ogv"
when using videos from dropbox you get rid of everything after the filename, and change www > dl
of course I am not sure if the videoplayer supports .ogv a good test is try playing the video locally, if video player can play the file type locally it should be able to do it from a url.
Audio is not playing for that video? What's the issue ?
did you create and assign an audio source? if you do have an audio source I would suggest pulling the video directly into your project to see if you can get audio working. cause it could be a codex issue. let me know how it goes.
I have a problem when strea$$anonymous$$g the video in android where it only able to stream like the first 10 seconds of the video then it suddenly stops strea$$anonymous$$g. But the video player works fine in the editor. Do you know any solutions to this issue?
Hello! I am at the same step, I have the video lag problem. The time of this delay is 5 seconds, how to solve this problem? please help!
Finally, i can play videos via URL. Thank You so much.
Answer by Lilo_stitch · Feb 08, 2019 at 05:26 PM
First upload the video on your dropbox by clicking upload file .. Once it is uploaded click share button you will find button called 'copy link 'click it ...
if your url was like this 'https://www.dropbox.com/s/r0zz33afd5khmcr/MyFriendWhatIfMyTourWasWithYou.mp4?dl=0' go to unity and add video player
make two changes to the url ..First one is replace 'www' with 'dl' ..Second one , at the end instead of dl=0 make it equal 1 ( look at the second screenshot and compare the url with one written above )
Wow this is super helpful, thank you a lot! This only works for me in the editor however... when I upload the build to my website with the dropbox link in the videoplayer as you showed, the video doesn't show up. Am I doing something wrong? It also doesn't work if I "build and run" the game.
Answer by erez1158 · Oct 12, 2019 at 07:16 PM
I'm facing the same issue, only that I'm trying to stream a video from Vimeo. Is there any changes I need to make in order for the VideoPlayer be able to read the URL?
Your answer
Follow this Question
Related Questions
while using Handheld.PlayFullScreenMovie playing url video stream, where it store the stream? 0 Answers
play back 360 video STEREO on GearVR 1 Answer
Video Player URL Stream Dropbox Video in Android Has Bug, but works fine in editor 0 Answers
Video streaming from a web server in android 0 Answers
Playing Video in Unity 5 (on mobile) 4 Answers