50

HTML5 videos always start at 100% volume.

How can I make them start at 50% volume?

supercoolville
  • 8,636
  • 20
  • 52
  • 69
  • Google chrome stable version 67 fixed this by disabling the volume controls on html5 video player, and basically forcing volume to always be at 100% full. For details see: https://productforums.google.com/forum/#!topic/chrome/2lN8hckg9cg – Eric Leschinski Aug 25 '18 at 04:29

8 Answers8

54

Assuming you're good with mixing JS into your HTML, you can leverage one of the events, such as loadstart:

<video onloadstart="this.volume=0.5" ...>
dwelle
  • 6,894
  • 2
  • 46
  • 70
  • 2
    simplest answer! If only the W3C saw fit to give us a volume attribute to go along with our muted one. – Grae Kindel Jun 13 '16 at 21:08
  • 1
    All the answers are hacks, but this one at least puts the code close to the action. Although there is an argument for unobtrusiveness, I think this is a worthy exception to allow legacy coders to see why the volume is starting at 50%. – Enigma Plus Dec 15 '16 at 09:45
  • 1
    I don't know why, but onLoadStart doensn't seem to work for me (in React) – Shahriar Jul 27 '22 at 18:12
  • @Shahriar https://rp40jo.csb.app/ – dwelle Jul 27 '22 at 21:10
  • @dwelle The example works correctly, but my code still doesn't. I also tried `onLoadStart={(e) => console.log(e)}` but no seems like onLoadStart doesn't even fire. – Shahriar Jul 27 '22 at 21:39
41

You can affect the volume property of the <video> element as follows:

document.getElementsByTagName('video')[0].volume = 0.5;

If using jQuery then you can use their prop method to alter the volume in a jQuery collection object like so:

$("video").prop("volume", 0.5);

This will alter all DOM elements in the collection.

chrki
  • 6,143
  • 6
  • 35
  • 55
marksyzm
  • 5,281
  • 2
  • 29
  • 27
  • Small addition for those who don't know: this code needs to be put in browser's add-on "*monkey"(there are different implementations). – Alex Barkun Dec 05 '19 at 14:46
36
var video = document.getElementById('player');
video.volume = 0.5;

P.S. Use this script for compatibility.

Ernestas Stankevičius
  • 2,420
  • 2
  • 24
  • 30
21
<div>
    <video id="sampleMovie" src="mp4/Premier delivery.mp4" width="777" height="582.75" controls autoplay ></video>
        <script>
        var video = document.currentScript.parentElement;
        video.volume = 0.1;
        </script>
    </div>

Works perfectly!

Daniel Sokolowski
  • 11,982
  • 4
  • 69
  • 55
Michael Hall
  • 331
  • 2
  • 3
3

If you don't want to mess with javascript, you can do it like this:

<video muted="">
    <source src="yourvideo.mp4" type="video/mp4">
</video>
Paul
  • 103
  • 1
2

With jQuery need to use a little trick:

$('#your_video_id').get(0).volume = 0;
Flexo
  • 87,323
  • 22
  • 191
  • 272
Stan
  • 21
  • 1
1

Setting the default volume, using jquery:

$(function() {
    $("video").each(function(){ this.volume = 0.5; });
});
tmpsa
  • 19
  • 1
0

The React way using useCallback

import { useCallback } from "react"

const vid = useCallback((x) => x.volume = 0.5)

return (
    <video ref={vid} />
)
Shahriar
  • 1,855
  • 2
  • 21
  • 45