Search Unity

Bug Audio volume on WebGL cannot be muted

Discussion in 'Audio & Video' started by inkletom, Aug 4, 2020.

  1. inkletom

    inkletom

    Joined:
    Oct 13, 2016
    Posts:
    63
    It seems that audio can't be controlled using an audiosource via video played in WebGL.
    VideoAudioOutputMode.None doesn't mute video when played in WebGL either.
    Using VideoAudioOutputMode.Direct & SetDirectAudioVolume(0,0) works on Chrome, but not on Edge.

    Is this known? Is there a workaround?
     
    andylukito97 likes this.
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi!

    Indeed, the audio form the VideoPlayer can only be played straight to the output device and cannot go through AudioSource for further processing. This is a limitation of the html5 video support, where audio samples are not accessible. For more flexible audio control, you can consider splitting the audio from your movie file into a separate asset and play this separately at the same time.

    There's also a direct mute control that you can try, but setting the volume should work. Make sure the audio output mode is done before preparing/playing the movie; this is a setting that cannot be changed while playback is ongoing, so it's not the appropriate way to mute/unmute.

    The intended sequence of events is
    1. Set the audio output mode to direct
    2. Set the initial volume/mute you want using the VideoPlayer SetDirectAudioVolume or SetDirectAudioMute methods.
    3. Start playing the movie
    4. Make other adjustments to volume/mute
    If this doesn't seem to be working on Edge, then we're looking at a browser-specific behaviour that we may be able to work around. Please file a bug with a scene that contains the logic you're using to drive the VideoPlayer and we'll have a look.

    Thanks for bringing this to our attention!

    Dominique Leroux
    A/V developer at Unity
     
    andylukito97 likes this.
  3. inkletom

    inkletom

    Joined:
    Oct 13, 2016
    Posts:
    63
    Thanks for the info! Testing with a fresh project, SetDirectAudioVolume does seem to work - I imagine something else was to blame!
    I've also just noticed that VideoPlayer.EnableAudioTrack doesn't work on Chrome, but does in Edge.

    It's been a bit tricky working with WebGL just because there's not much info on exactly what works and what doesn't - it's a small miracle WebGL works at all so it's great we're able to do most of what we need, but it's a shame how long it's taken us to get a clear picture of how to go about it.

    It'd be great if the unsupported functions logged to the console if they don't work on the current platform, or if they worked via a different method - if VideoAudioOutputMode.None worked on WebGL using the same underlying code that allowed volume to be set using SetDirectAudioVolume, for example.

    Ta!

    Tom
     
    kobi666 likes this.
  4. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,084
    It also does not work on Chrome or Safari.
     
  5. andylukito97

    andylukito97

    Joined:
    Nov 18, 2019
    Posts:
    3
    I've tested this on my webGL project Unity 2019.4.9f1
    Played a video, then tried changing the volume through the audio source but there's no effect. Debugged it as well, the script seems to be working just fine.
    Followed DominiqueLrx advice on just using the direct output mode.

    Does this bug affect mobile as well? I've tested this on android and the same thing occurred.