tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

simpleaudio.volume don't work in cordova ios #235

Closed metalalchemist closed 1 year ago

metalalchemist commented 1 year ago

well i'm write a slider for a volume efects and music for my game. when i compiled for android it works perfectly. but when i made for ios it don't work. i tested in my pc with Microsoft edge, in my mac with Safary and in my android with webview. in all device it works. only in ios don't work. here is my code.

<label for="vmusica" id="smusica">Volumen de la música</label><input type="range" min="0" max="100" step="10" id="vmusica">
<label for="vefectos" id="sefectos">Volumen de los  efectos de sonido</label><input type="range" min="0" max="100" step="10" id="vefectos">
<script>
function volumenEfectos() {
SugarCube.State.variables.vefectos=parseFloat(document.querySelector("#vefectos").value/100);
}
function volumenMusica() {
SugarCube.State.variables.vmusica=parseFloat(document.querySelector("#vmusica").value/100);
SugarCube.SimpleAudio.select(":playing").volume(SugarCube.State.variables.vmusica);
}
document.querySelector("#vmusica").addEventListener("change", volumenMusica);
document.querySelector("#vefectos").addEventListener("change", volumenEfectos);
}
</script>

I changed change event for input event and for touchend event but don't work. i'm using sugarcube 2.36.1 and tweego 2.1 any ideas? thanks. in i use fadeout don't slow volume and stop suddenly. sorry my english is so bad.

metalalchemist commented 1 year ago

https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html

greyelf commented 1 year ago

For any one else wondering why audio volume can't be programmatically adjusted...

As noted in the 2nd of the points in the Audio limitations section of SugarCube's SimpleAudio API documentation...

  1. In mobile browsers, playback volume is controlled by the device hardware. Thus, all volume adjustments are ignored by the device, though muting should work normally.

...and in the 3nd of the points in the Volume Control in JavaScript section of Apple's iOS-Specific Considerations documentation that the original posted linked to...

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

...the volume of audio on an iOS based device is only controllable using the physical controls of the device itself.