<button onclick='playPause()'><i aria-hidden='true' id='myicon'/></button> <button onclick='player.volume = Math.min(player.volume * 1.2, 1)'><font size='+1'><i aria-hidden='true' class='fa fa-volume-up'/></font></button> <button onclick='player.volume /= 1.2'><font size='+1'><i aria-hidden='true' class='fa fa-volume-down'/></font></button> There is a working audio player on JS. Everything works as expected (in the desktop), but: the android at full stop "does not see" the preset volume (0.2) and starts the volume higher (according to the sensations - 0.5). And the first time you press volume up (+ volume) instead of increasing the sound, the set value is executed: resets the sound by 0.2. Then everything works as it should. The bug occurs only during the first launch. And only in android. Where is the mistake?
<script> var mysrc = "http://радиостанция.mp3"; var player = new Audio(mysrc); var myicon = document.getElementById("myicon"); var current_volume = player.volume = 0.2; if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){ myicon.className = "fa fa-play"; }else{ myicon.className = "fa fa-spinner fa-pulse fa-1x fa-fw"; player.addEventListener('loadeddata', function(){ myicon.className = "fa fa-play"; }, false); } function playPause(){ if(player.paused){ player.play(); if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { myicon.className = "fa fa-spinner fa-pulse fa-1x fa-fw"; setTimeout(function(){ myicon.className = "fa fa-pause"; player.volume = current_volume; }, 3000); }else{ myicon.className = "fa fa-pause"; } }else if(player.muted==true){ player.muted=false; player.volume = current_volume; myicon.className = "fa fa-pause"; }else{ current_volume = player.volume; player.muted=true; myicon.className = "fa fa-play"; } } </script>