Ivan
Ivan

Reputation: 311

volume off does not work in html5 video ipad 2

volume off does not work in html5 video ipad 2.

player = document.getElementById(element_id);
if (player.muted){
    player.muted = false;
    player.volume = 1;
    //player.volume(1);
}else{
    player.muted = true;
    player.volume = 0;
    //player.volume(0);
}

Upvotes: 5

Views: 7486

Answers (2)

Noahdecoco
Noahdecoco

Reputation: 211

I've been able to achieve something like this by doing the following:

  • To mute, remove the entire element. Easily done if you're using jquery.

    $('#audio-elem').remove();

  • To unmute, simply add it back in!

    $('body').append('');

I did find two issues with this method though:

  • The iPad doesn't cache audio so it needs to reload it when added back in. That means there will be a delay before the audio starts playing again.
  • The audio will play from the start, that is 00:00, when loaded back in.

Hope it helps!

Upvotes: -2

brianchirls
brianchirls

Reputation: 7853

I'm afraid iOS does not allow changing the volume with Javascript. From Apple's documentation (emphasis is mine):

On the desktop, you can set and read the volume property of an or element. This allows you to set the element’s audio volume relative to the computer’s current volume setting. A value of 1 plays sound at the normal level. A value of 0 silences the audio. Values between 0 and 1 attenuate the audio.

This volume adjustment can be useful, because it allows the user to mute a game, for example, while still listening to music on the computer.

On iOS devices, the audio level is always under the user’s physical control. The volume property is not settable in JavaScript. Reading the volume property always returns 1.

There is no mention of the muted property, but experimenting shows that it can't be changed either: http://jsbin.com/anikab/1/

Upvotes: 13

Related Questions