Skip to content

Commit a060d3f

Browse files
committed
Remove event listeners in deleteMusic()
1 parent 1ce1cac commit a060d3f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

music_html5.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ static int MusicHTML5_Open(const SDL_AudioSpec *spec)
8282

8383
// TODO: Match blob by ptr and size so we don't duplicate
8484

85-
if (!(url in Module["SDL2Mixer"].blob))
86-
Module["SDL2Mixer"].blob[url] = 0;
87-
Module["SDL2Mixer"].blob[url]++;
85+
if (!(url in this.blob))
86+
this.blob[url] = 0;
87+
this.blob[url]++;
8888

8989
return url;
9090
},
@@ -97,16 +97,17 @@ static int MusicHTML5_Open(const SDL_AudioSpec *spec)
9797
},
9898

9999
createMusic: function(url, context) {
100-
const id = Module["SDL2Mixer"].getNewId();
101-
Module["SDL2Mixer"].music[id] = new Audio(url);
102-
Module["SDL2Mixer"].music[id].addEventListener("ended", Module["SDL2Mixer"].musicFinished, false);
103-
Module["SDL2Mixer"].music[id].addEventListener("error", Module["SDL2Mixer"].musicError, false);
104-
Module["SDL2Mixer"].music[id].addEventListener("abort", Module["SDL2Mixer"].musicInterrupted, false);
105-
// Can browser recover from these states? If not, consider enabling these.
106-
//Module["SDL2Mixer"].music[id].addEventListener("stalled", Module["SDL2Mixer"].musicInterrupted, false);
107-
//Module["SDL2Mixer"].music[id].addEventListener("suspend", Module["SDL2Mixer"].musicInterrupted, false);
100+
const id = this.getNewId();
101+
this.music[id] = new Audio(url);
102+
this.music[id].addEventListener("ended", this.musicFinished, false);
103+
this.music[id].addEventListener("error", this.musicError, false);
104+
this.music[id].addEventListener("abort", this.musicInterrupted, false);
105+
// Can browser recover from these states? If not, consider enabling these
106+
// as well as the corresponding removeEventListeners in deleteMusic().
107+
//this.music[id].addEventListener("stalled", this.musicInterrupted, false);
108+
//this.music[id].addEventListener("suspend", this.musicInterrupted, false);
108109
if (context)
109-
Module["SDL2Mixer"].music[id].dataset.context = context;
110+
this.music[id].dataset.context = context;
110111
return id;
111112
},
112113

@@ -121,6 +122,12 @@ static int MusicHTML5_Open(const SDL_AudioSpec *spec)
121122
this.music[id].load();
122123
this.music[id].remove();
123124

125+
this.music[id].removeEventListener("ended", this.musicFinished, false);
126+
this.music[id].removeEventListener("error", this.musicError, false);
127+
this.music[id].removeEventListener("abort", this.musicInterrupted, false);
128+
//this.music[id].removeEventListener("stalled", this.musicInterrupted, false);
129+
//this.music[id].removeEventListener("suspend", this.musicInterrupted, false);
130+
124131
delete this.music[id];
125132

126133
this.deleteBlob(url);

0 commit comments

Comments
 (0)