• I would like to add code to each video block to set an initial playback volume. This is a voiceover reel and the video volumes are inconsistent. Since some of them are playing via Vimeo etc., the only way I can match them is to tweak their playback levels. Can someone shoot me a way to add to the code to set each video with it’s own volume? Thank You!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The HTML5 video player element has a .volume property you can set (as a decimal fraction between 0 and 1) with JavaScript, but embedded players from streaming services typically have their own players within iframes which your JS cannot access. In some cases such players might accept an attribute value in the iframe tag to set a volume level. Availability of such an option will vary by provider.

    Thread Starter dhartmusic

    (@dhartmusic)

    Thanks bcworkz,
    Even if I can only set the volumes for the uploaded files it will help as generally they are louder than the streamed files. Not quite sure how to add the JS. This is the html for the video block:

    <figure class=”wp-block-video”><video controls src=”http://www.mellodeevo.com/wp-content/uploads/2023/01/You-and-Us_v16.movSmall.mov”></video></figure&gt;

    Here is the script from the page you linked:

    const obj = document.createElement(‘audio’);
    console.log(obj.volume); // 1
    obj.volume = 0.75;

    Not sure how to implement.

    Moderator bcworkz

    (@bcworkz)

    Sorry, that example isn’t very useful. The link was merely to document that a video player has a volume property that we can manipulate. This sets the volume of the first video player found to 70% (untested):

    <script>
    var vids = document.getElementsByTagName('video');
    if ( 0 < vids.length ) { vids.item(0).volume = 0.7; }
    </script>

    You cannot place this code through the post editor, it’ll get corrupted. Probably the simplest way to place it is to put it on the relevant post template. If your theme is subject to periodic updates, you should keep the modified template in a child theme. As a test it’s OK to modify the template where it sits, but it’s not a good long term solution.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Video block initial volume’ is closed to new replies.