Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to Play Youtube Video in Unity Webgl

Discussion in 'Web' started by RahmatAli_Noob, Aug 23, 2023.

  1. RahmatAli_Noob

    RahmatAli_Noob

    Joined:
    Sep 13, 2022
    Posts:
    73
    Hi Everyone, I am Making the WebGl project in Which I need to Play the YouTube Video.
    I have Checked Most of the Assets on the Unity Asset Store or on the google. Some of them Claims to Work But is not Working.
    I Have tried 2 Most Claiming assets.
    1 - This, they Claim that there assets work fine but It Didn't Work in both the free version or in purchase version.
    2- This, this is free Asset but Require the License key to check the Demo project and the Demo license key is not Working. Also I Have Contacted with their Team but there is no response from them Yet.

    I am Looking for this Solution about 2 Weeks Now.
    Is there Any Solution on Unity To play the YouTube Video In Webgl or Not?
    Thanks In Advance.
     
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    Unfortunately I am not aware of any mechanism that Google would allow YouTube videos to be embedded without the use of their video player widget. Their own supplied video player widget is Google's official solution that adheres to their embedding licensing rules.

    See https://www.w3schools.com/html/html_youtube.asp how that would work on normal non-WebGL HTML pages.

    But unfortunately that video player widget does not support being embedded inside a 3D WebGL Canvas.

    Looking at the first asset store asset, they mention "webgl(chrome, firefox) use third party server to get the video urls". So what that means is that they work around Google's official video player widget by ripping the videos onto a transparent proxy server that they host somewhere.

    The second asset store package does not mention their details. I presume they will be doing something similar.

    Searching the web, it looks like developers of Google's Chrome web browser prototyped a solution for this six years ago, at https://github.com/toji/webgl-iframe/tree/master . However running the code today does not work (and looks like it never worked in public Chrome, but only in their internal test builds). In https://github.com/toji/webgl-iframe/issues/2 they mention

    "
    This project only worked with a locally-patched prototype version of Chromium, but we are no longer working on it. I don't think we will ever add this support in Chromium.
    "

    It does seem like the video proxy solution from asset store package 1 would be the straightforward method, if the asset store package author can help make it work. But do check YouTube's licensing and ask the asset store package author about licensing to make sure the mechanism is adhering to YouTube's licensing.
     
  3. tylergregg

    tylergregg

    Joined:
    Aug 6, 2012
    Posts:
    6
    jukka_j and mgear like this.
  4. ontreus

    ontreus

    Joined:
    May 18, 2015
    Posts:
    2
    Hi, I tested your example and the important thing is that it works in WEBGL, but could you create a simpler example. One without the player moving. Just a VideoPlayer
    Because I had difficulty replicating your model. When I tried, my video had no sound and was upside down. Thanks