Search Unity

Video VideoPlayer cannot play url http://www.youtube.com/watch?v= ...

Discussion in 'Audio & Video' started by RoyandDestroy, Jul 10, 2018.

  1. RoyandDestroy

    RoyandDestroy

    Joined:
    Apr 16, 2018
    Posts:
    2
    Hi,
    I am trying to show a video from a url on a texture using the Video Player.
    I tried several urls, some worked well but I can't seem to be able to play videos directly from their youtube URLs,

    Is that happening because the URL contains more than the video itself?
    Does anyone have a way to show youtube videos using the Video Player?

    Thank you for your time,
    Roy.
     
  2. DVFrance

    DVFrance

    Joined:
    Jul 9, 2012
    Posts:
    20
    Hi,

    Facing the same issue here, have some news ?
     
  3. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    The Video Component doesn't have youtube functionality. The url should point to some video file which is either local or from a server. Since youtube doesn't use absolute urls to video's it won't work.
     
    fritzjaeggi2109 and leftshoe18 like this.
  4. DVFrance

    DVFrance

    Joined:
    Jul 9, 2012
    Posts:
    20

    Thx for this precision
     
  5. unity_eaKm_7FNf4Uaww

    unity_eaKm_7FNf4Uaww

    Joined:
    Mar 14, 2019
    Posts:
    6
    did any body gets any sloution for
    VideoPlayer cannot play url http://www.youtube.com/watch?v= ...

    ---

    My question is how to stream youtube videos to unity
     
  6. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Unity's built-in VideoPlayer component cannot play youtube video's, find a plugin on the Asset Store that does support it. There is probably one out there somewhere.
     
  7. unity_eaKm_7FNf4Uaww

    unity_eaKm_7FNf4Uaww

    Joined:
    Mar 14, 2019
    Posts:
    6

    Non of them are free.
     
  8. johnnydel2019

    johnnydel2019

    Joined:
    May 21, 2019
    Posts:
    1
    Yes I am also having this problem
     
  9. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    270
    I assumed the Videoplayer component would work for youtube videos, It doesn't.

    SAD TIMES
     
    bettywhite and janhildebrand like this.
  10. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    I am looking to play different video according to different images in my AR project.Tried many attempts like downloading them and play that video or trying to play directly from server(.mp4 and .webm videos).I created a cube(prefab) and trying to play video on it.
    Code (CSharp):
    1. public void OnImageChanged(ARTrackedImagesChangedEventArgs args)
    2. {
    3.     foreach (var trackedImage in args.added)
    4.     {      
    5.         isRunning = true;//Continuing to update
    6.     }
    7.  
    8.     foreach (var trackedImage in args.updated)
    9.     {
    10.         //Below condition is true
    11.         if (File.Exists(Application.persistentDataPath + "/video.mp4") && isRunning==true)
    12.         {
    13.             Debug.Log("Yes File Exits");
    14.  
    15.  
    16.             var vp = mTrackedImagePrefab.AddComponent<VideoPlayer>();//cube prefab
    17.             vp.source = VideoSource.Url;
    18.             vp.url = "https://www.videvo.net/videvo_files/converted/2014_12/preview/ULTRASOUND_3.mov74497.webm";//Tried another video with mp4 format
    19.             //vp.url = Application.persistentDataPath + "/video.mp4";//Play locally downloaded file-Not working
    20.  
    21.             vp.isLooping = true;
    22.             vp.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
    23.             vp.targetMaterialRenderer = GetComponent<Renderer>();
    24.             vp.targetMaterialProperty = "_MainTex";
    25.             vp.Play();
    26.             isRunning = false;//stop update
    27.  
    28.         }
    29.  
    30.     }
    31. }
    The error displayed is "Cannot Play a disabled VideoPlayer ".Testing-I added a video player to the prefab manually and assigned a video clip,at that time the video was playing but I want to play from a URL or download them and play it on the cube.
     
  11. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    VideoPlayer
    component has to be
    enabled
    . So make sure the
    mTrackedImagePrefab
    is actually active in the hierarchy before calling
    Play


    Also make sure webm is a supported format. I'd usually stick with mp4 as those tend to work on most platforms unless encoded wrong or too high resolution etc.

    It's been a while for me since I've touced any AR stuff so, I'm not up to date with the API and processes.
    mTrackedImagePrefab
    is a scene instance? Is it active in the hierarchy before you request to Play?
    if not then that's why you get a "Cannot Play a disabled VideoPlayer".
    You could try adding
    if(!mTrackedImagePrefab.activeInHierarchy) Debug.LogError("Not active in hierarchy", mTrackedImagePrefab);

    As for playing videos on iOS & Android, I usually don't have any trouble playing mp4's.

    To debug/test whether it is something in the AR loop or something with the video or device...
    You could just create a GameObject in the scene, attach a VideoPlayer to it. Configure it how you would configure it in code and then just let it play On Awake. Build and check whether it runs or not.

    Also not certain anymore if you need file:/// for the local url. But you could try it out.
     
    zyonneo likes this.
  12. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    "To debug/test whether it is something in the AR loop or something with the video or device.You could just create a GameObject in the scene, attach a VideoPlayer to it. Configure it how you would configure it in code and then just let it play On Awake. Build and check whether it runs or not."

    Tried this and looks like mTrackedImagePrefab is instantiated when Image is detected.So I added the line
    GameObject cubePrefab =GameObject.FindWithTag("VidPlayer"); then added video player to that cubePrefab and code to play the video and it worked.
     
  13. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Careful with FindWithTag, in this case it will work but if multiple game objects are tagged with the same tag it will try to find any game object with the tag. So it might not even be the game object you actually wanted it to be.
     
    zyonneo likes this.
  14. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    Will keep that in mind.Will constantly test if there is any issues.If any will try to find another solution
     
  15. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    As you said it is causing problems...So I created a prefab and instantiated while image is detected.Now looking for the prefab (cube) to play corresponding video and it should hide when the image tracking is not there.When I show next image the cube should play video according to that image(different video) but on the same cube.Is it possible?
    Read in some forums that args.removed does not give anything in return.

    EDIT- I tried using dictionary.Looking to hide gamobjects which was instatiated by image.When new image is shown hiding old gameobject.
    Code (CSharp):
    1.  
    2.  public void OnImageChanged(ARTrackedImagesChangedEventArgs args)
    3.     {
    4.  
    5.         foreach (var trackedImage in args.added)
    6.         {
    7.             Debug.Log("Instantiate Cube");
    8.             cubePrefab = Instantiate(cubeTv, trackedImage.transform);
    9.  
    10.             var data = allDataContent.FirstOrDefault(i => i.imgFileName == trackedImage.referenceImage.name);
    11.             videoName = data.vidFileName;
    12.      
    13.             vp = cubePrefab.GetComponent<VideoPlayer>();
    14.             vp.source = VideoSource.Url;
    15.             vp.url = Application.persistentDataPath + "/" + videoName;  
    16.             vp.playOnAwake = true;
    17.             vp.isLooping = true;
    18.             vp.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
    19.             vp.targetMaterialRenderer = GetComponent<Renderer>();
    20.             vp.targetMaterialProperty = "_MainTex";
    21.             vp.Play();
    22.  
    23.             holdList.Add(cubePrefab, trackedImage.referenceImage.name);//adding instantiated GamObject to Dictionary
    24.            
    25.         }
    26.         foreach (var trackedImage in args.updated)
    27.         {
    28.  
    29.  
    30.             if (trackedImage.trackingState == TrackingState.Tracking)
    31.             {
    32.                 var data = allDataContent.FirstOrDefault(i => i.imgFileName == trackedImage.referenceImage.name);
    33.                 videoName = data.vidFileName;
    34.                 if (File.Exists(Application.persistentDataPath + "/" + videoName))
    35.                 {
    36.          
    37.                     foreach (var v in holdList.Values)
    38.                     {
    39.                          GameObject go = holdList.FirstOrDefault(x => x.Value == trackedImage.referenceImage.name).Key;
    40.                          if (v == trackedImage.referenceImage.name)
    41.                          {
    42.                  
    43.                              go.SetActive(true);
    44.                              continue;
    45.                          }
    46.                          else
    47.                          {
    48.                             // go.SetActive(false);// Crashing after using this
    49.                  
    50.                          }
    51.                      }
    52.                  }
    53.  
    54.            }
    55.    
    56. }
    57.  
     
    Last edited: Apr 27, 2020
  16. fracmon88

    fracmon88

    Joined:
    May 4, 2020
    Posts:
    1
    Hello! Maybe what you should do to make it work well is to download the video from youtube (with online app's like https://www.descargarclip.com/videos-youtube/) and then embed the already downloaded video... maybe the way you try to do it will not allow Unity. Try this way and tell us!
     
    Last edited: May 4, 2020
  17. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Embedding the video into the application will make the binary also fatter.
    Also downloading video's from youtube probably ain't completely legal either. Sure it is possible but legal is another question. But I ain't a lawyer nor do I know the law by heart.

    But yeah embedding the video would be the same as just importing any other video. Most of those should work as long as you use the encoding that goes with the target platform. If that doesn't work you should file a bug report.
    I've filed so many bug reports over the years and they have fixed quite a lot because of those. So yeah it does help! Maybe not at the pace you want it to, I mean sometimes it takes them a month or 2 to fix the issue but the process behind it is slow.

    In my case the VideoPlayer is often broken, at the moment on WebGL for playing from a url and on Android for the Oculus GO, multiple video's playing at the same time on separate objects you get that video's are cross playing. Meaning it is completely random which texture they take. Video A could be playing on GameObject B for a few frames and then suddenly Video B takes over GameObject B. As if the video player is taking the wrong texture pointer or the video player is writing only to 1 texture which unity reads from. It is one hell of a bug.
     
  18. epicsportsfun

    epicsportsfun

    Joined:
    May 6, 2020
    Posts:
    1
    I guess you can instead try using the embed code in the page just like what i have tried on mycfavisit portal which is actually working without any kind of issues and it works for you too I guess.
     
  19. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    That totally depends on the platform. If it is WebGL then yes you could possibly embed it into the native browser page instead of Unity.