Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
adding setVolume to bgmusic
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Nov 13, 2016
1 parent b8f8367 commit d635742
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bgmusic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ bgmusic = {

}
},
changeVolume: function(volume){
if(this.playing in resources.music){
resources.music[song].setVolume(volume);
}
},
pushSong: function(){
var song = this.playing;
this.songStack.push({ song: song,
Expand Down
7 changes: 7 additions & 0 deletions src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ resources.harvest = function(callback) {
// play sound
resources[resDict.to[0]][resDict.to[1]].source.start(resources[resDict.to[0]][resDict.to[1]].currentTime);
}
resources[resDict.to[0]][resDict.to[1]].setVolume = function(volume){
resources[resDict.to[0]][resDict.to[1]].volume = volume;
resources[resDict.to[0]][resDict.to[1]].gainNode.gain.value = resources[resDict.to[0]][resDict.to[1]].volume;
}
}
})(resDict,request) /* decodeAudioData success */, function(err) {
throw new Error(err);
Expand All @@ -306,6 +310,9 @@ resources.harvest = function(callback) {
resources[resDict.to[0]][resDict.to[1]] = document.createElement('audio');
resources[resDict.to[0]][resDict.to[1]].id = resDict.to[1];
resources[resDict.to[0]][resDict.to[1]].loop = true;
resources[resDict.to[0]][resDict.to[1]].setVolume = function(volume){
resources[resDict.to[0]][resDict.to[1]].volume = volume;
}

//I am having trouble loading using audio.src, instead a XMLHttpRequest
//is a more flexible way to load audio. I don't know if the problem
Expand Down

0 comments on commit d635742

Please sign in to comment.