LLLLLLL Posted August 6, 2012 Share Posted August 6, 2012 I have an HTML5 audio player that gets created dynamically. Elsewhere the variable is declared: var default_volume = 0.8; Then I set the volume for the player ... player.setAttribute( 'volume', default_volume ); Debugging shows default_volume is 0.8, but once set, "volume" is changed to 1 Why is there rounding? How can I make it maintain the value I chose? Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/ Share on other sites More sharing options...
requinix Posted August 6, 2012 Share Posted August 6, 2012 Well that would be the player itself changing the value, wouldn't it? What player? Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367349 Share on other sites More sharing options...
LLLLLLL Posted August 6, 2012 Author Share Posted August 6, 2012 Player is an audio element var player = document.createElement( 'audio' ); player.setAttribute( 'volume', default_volume ); Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367363 Share on other sites More sharing options...
requinix Posted August 7, 2012 Share Posted August 7, 2012 And HTML 5 does say it's a value between 0.0 and 1.0. What browser? And is the volume being set correctly (it's just that you can't get the right value)? Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367367 Share on other sites More sharing options...
Mahngiel Posted August 7, 2012 Share Posted August 7, 2012 does it round down? Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367373 Share on other sites More sharing options...
nogray Posted August 7, 2012 Share Posted August 7, 2012 If you use setAttribute, you would need to use getAttribute to see the value. e.g. var player = document.createElement( 'audio' ); player.setAttribute('volume', 0.; alert(player.getAttribute('volume')); // alerts 0.8 alert(player.volume); // alerts 1 // setting the volume directly player.volume = 0.8; alert(player.volume); // alerts 0.8 Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367380 Share on other sites More sharing options...
LLLLLLL Posted August 7, 2012 Author Share Posted August 7, 2012 Yes , I thought about that right before going to sleep last night... just set it directly. Appears to be it. Quote Link to comment https://forums.phpfreaks.com/topic/266744-why-does-the-variable-become-rounded/#findComment-1367408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.