Search Unity

Video Four core bugs in VideoPlayer, and how to workaround them

Discussion in 'Audio & Video' started by a436t4ataf, Apr 25, 2020.

  1. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    After a very miserable and stressful week, I've logged four major bugs in VideoPlayer - as far as I can tell, the Unity team just isn't bothering to test it with WebGL builds. It's out-of-the-box broken in multiple ways, across the most widely-used browser, and in some ways across ALL browsers.

    For reference, and to help anyone else trying to get Unity to play video in a browser (which is very difficult with so many bugs, and having to wait for the painfully slow build every time you want to test even a one line code change), here's what I've found (notes on how to workaround some of these - see below):

    1. (Case 1241263) Builds always corrupt all video, converting them to WMV on Windows, when spefically told not to
    2. (Case 1241581) VideoPlayer incorrectly triggers browser anti-spam by playing fake audio even for videos that have no audio track

    3. (Case 1241582) VideoPlayer ignores the AudioOutput mode and causes Chrome to BLOCK all video playback
    4. (Case 1241584) VideoPlayer ignores the muted state of videos, causing browsers to block the video

    There's also another one that I didn't report, but caused me a lot of disappointment :) :

    5. VideoPlayer's implementation of the "clip" playback mode is fundamentally broken and will always fail in WebGL

    Workaround for that gradually took me through discovering the other bugs. As I said: Unity is clearly not testing their own code here. Searching Google etc shows that some of these are confirmed reported to Unity 8+ months ago and still not fixed yet, and others may have been around even longer.

    ---

    What you need to know:

    • You cannot use "clips". As far as I can tell, Unity isn't testing them, so my recommendation: don't even bother trying
      • e.g. With 2019.3, Unity corrupts all clips in the project when doing WebGL builds. Unity ignores the import settings for the files, and force-transcodes them to a proprietary Chrome-only, Windows-only format.
      • e.g. Even if you set the transcoder settings explicitly - Unity ignores you, overrides your settings, and corrupts your clips. Most browsers will never be able to play your clip.
      • Workaround: learn how to use the magic "StreamingAssets" folder (note: it must be spelt exactly that way, and it MUST be in the root of your project, it will fail otherwise), this is documented in the Unity manual.
    • VideoPlayer requires a ONE LINE fix to make it support StreamingAssets, but the team for some reason chose not to do this themselves, you have to do it:
      • Amusingly, this oneline fix is provided by Unity! It's in the official docs page for the StreamingAssets folder! (It's almost as if someone there was trying to poke the people who wrote VideoPlayer into fixing their code ;), by giving them a free example of how to workaround their bug with Clips)
    • VideoPlayer generates fake audio, causing all browsers to crash on auto-play
      • Never ever tick the box "Play on Awake" -- it's fundamentally broken
      • Note: muting the audio (using the VideoPlayer API) won't work (broken)
      • Note: removing the audio track from video won't work (broken)
      • Note: deleting the camera's AudioListener won't work (although I didn't expect it to - but I tried anyway)
    • VideoPlayer's implementation of Prepare() is broken and crashes Chrome
      • This one is probably not Unity's fault, it is a bug in Chrome, but they have known about it for almost 10 months and the fix is still "Pending". All other platforms I could find that were affected by this bug in Chrome fixed the bug in their own code last year, so it's an open question why Unity hasn't pushed their fix to live yet.
      • Most likely: it creates or uncovers some other bug(s) in Unity's build-pipeline, or in VideoPlayer, and they're having to fix those too, now that they've been discovered.
    Hopefully some of the above will help people. As/when Unity responds to the bug reports, I'll update this. I have a horrible feeling some of these will be closed with WONTFIX, because the team has been disbanded or something (otherwise I can't imagine how e.g. the incompatibility with StreamingAssets wasn't fixed long long ago). But I am ever optimistic!