angular-soundmanager2
angular-soundmanager2 copied to clipboard
Volume resets when loading new file in player
When playing a track and setting the volume, if you change track the volume resets to the default volume of 90. The value of "Volume: " in the player's HTML will remain at the last value set, but the actual volume would have reverted to default.
I noticed on inspection of the JS (snippet below [Ln: 4734 - 4744]) that the volume controls only set the volume of the current track being played by SoundManager, as soon as another track is loaded, the getVolume() function is called again and returns the default volume, until you change the volume again via the controls.
getVolume: function() {
return volume;
},
adjustVolume: function(increase) {
var changeVolume = function(volume) {
for(var i = 0; i < soundManager.soundIDs.length; i++) {
var mySound = soundManager.getSoundById(soundManager.soundIDs[i]);
mySound.setVolume(volume);
}
$rootScope.$broadcast('music:volume', volume);
};
@lthomas122 It seems a little difference between our case?
I use a tooltip to display the volume bar. When setting the volume value by dragging the volume bar, the the volume value displayed on webpage is fine. Everytime hovering on the volume button, the volume value is what I set before, but the volume value displayed on webpage is still 90.
I think we should change the value of volume variable displayed on the page in the meantime. But I don't know how to do that.
Any help is appreciated!!
So I did find a fix for this, but it was sometime ago now...
I will have a look for you when I have a chance and post my fix here.
On 24 Sep 2017 12:11, "Neven.Leong" [email protected] wrote:
@lthomas122 https://github.com/lthomas122 It seems a little difference between our case?
I use a tooltip to display the volume bar. When setting the volume value by dragging the volume bar, the the volume value displayed on webpage is fine. Everytime hovering on the volume button, the volume value is what I set before, but the volume value displayed on webpage is still 90.
I think we should change the value of volume variable displayed on the page in the meantime. But I don't know how to do that.
Any help is appreciated!!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/perminder-klair/angular-soundmanager2/issues/44#issuecomment-331702906, or mute the thread https://github.com/notifications/unsubscribe-auth/AMxp8VdWpb4CFfVXBti5DBBWKJ_ebPtpks5sljjzgaJpZM4HW5Jk .
@lthomas122 Sorry! I didn't check the response here in time. Thanks for you help. I will be waiting for you solution.
Can you explain the issue a little better for me @NevenLeung ?
Is it that the actual volume is resetting in the JavaScript, like my issue? Or is it that the UI is being a bit glitchy and resetting back to 90?
if it's the actual volume not the volume UI controls. I've just written this script, which should point you in the right direction, however I've not tested it, as the project that I used soundmanager on ended years ago.
Hopefully this helps:
getVolume: function() {
var sliderValue = document.getElementById('***PutSliderIdHere***').valueAsNumber;
var savedVolume = Number(document.cookie.replace(/(?:(?:^|.*;\s*)appVolume\s*\=\s*([^;]*).*$)|^.*$/, "$1"));
if ((volume != sliderValue ){
volume = sliderValue;
return volume;
}
else if(savedVolume.length){
volume = savedVolume;
sliderValue = savedVolume;
return volume, sliderValue;
}
else {
return volume;
}
},
adjustVolume: function(increase) {
var changeVolume = function(volume) {
for(var i = 0; i < soundManager.soundIDs.length; i++) {
var mySound = soundManager.getSoundById(soundManager.soundIDs[i]);
mySound.setVolume(volume);
document.cookie = "appVolume=" + volume;
}
$rootScope.$broadcast('music:volume', volume);
};