Search Unity

Video Getting WebGL to play videos

Discussion in 'Audio & Video' started by CCouto96, Oct 29, 2018.

  1. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Hello everyone! I was hoping I could get some help with something really important.

    I have a game that I made and the way my game works is that video clips play and the player clicks buttons to navigate to the next scene. My videos are set up as MovieTextures, which work fine on the EXE build. However, I am going to need it on a WebGL build and I know MovieTextures don't work with WebGL. I know I can switch my videos to VideoClip, which I did before, but the WebGL build never worked (it never played the video in the scene).

    I'm kind of lost on what to do here. My game will need to go on a website eventually and unless there is a way to get an EXE to work on a website, I am not sure what to do.

    Any help would be appreciated.

    Please let me know if you have any other questions. Thanks!
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
  3. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    How do I make it an absolute path on my computer? Or is there a way to get an online URL working? I tried using a Youtube video of mine but the URL didn't work for some reason.
     
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    You have to host it yourself, just like your webGL build you have to host it somewhere.
    Youtube video’s don’t work with the Video Player component of Unity, because they are not an absolute path to a file. So for that you will need an asset from the asset store.
     
  5. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Would that be the StreamingAssets plugin?
     
  6. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Okay, so I got it to play from a URL, which is a file path to where the video is on my computer, but when I export it, it still doesn't play the video.
     
  7. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Make sure it is an mp4 with h.264 encoding
     
  8. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    I am exporting from After Effects. Does the preset of it matter? Or do I just need to make sure it's an mp4 with h.264 encoding?
     
  9. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    I’d say just test a few small fragments so you don’t have to wait too long to see if it works.
    I don’t know any more specifics than it needing to be a .mp4 with h.264 encoding.
     
  10. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    It didn't work.
     
  11. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Is there a specific code I have to write in order to get it work on export? I read in some documentations that there's some code for streaming assets that goes like this:
    path = Application.dataPath + "/StreamingAssets";
    Do I have to put that somewhere in my code?
     
  12. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Like I said you need an absolute path. How you insert that in the video player url variable is up to you.
    You can serialize it or set it via script
    I don’t know out of mind if the Application.StreamingAssetsPath works in webgl. You’d have to test that...
    Just debug log the path and look it up in the console.

    If you have a server that is hosting the webgl build you probably end up with something like

    www.server.com/builds/webgl/streamingassets/MyVideo.mp4

    Where www.server.com/builds/webgl/streamingassets is returned by Application.StreamingAssetsPath.

    Like I said, don’t know out of mind. Test it.
    Simple empty scene with a script that does some debugs and sets the video url and starts it is all you need.
     
  13. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Okay, I'll see what I can do.
     
  14. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    I'm honestly not sure how to set it up via script since I am not really a programmer. Using a file path from my computer is all I really know.

    Also not entirely sure how to set up the debug log to test this specific issue.
     
  15. kiki234

    kiki234

    Joined:
    Nov 9, 2018
    Posts:
    2
    Youtube video’s don’t work with the Video Player component of Unity
     
  16. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Is there a way to host it on a website and get the video to play from there?
     
  17. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Hey guys. I'm still having trouble getting it to work. Can someone show me an example of a working URL that will play in both the editor AND the Web GL export?
     
  18. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Is there any code I have to attach to this in order for it to work?
     
  19. CCouto96

    CCouto96

    Joined:
    May 18, 2016
    Posts:
    44
    Is there a place I can host the videos and test it out to see if it works?
     
  20. blabberbytes

    blabberbytes

    Joined:
    Nov 22, 2014
    Posts:
    13
    I'm tryna figure this out too any luck?