Adding and removing listeners for relevant events

This commit is contained in:
Pavle Goloskokovic 2018-01-08 17:23:50 +01:00
parent 2d7e8c3403
commit 881d37080b

View file

@ -35,6 +35,13 @@ var HTML5AudioFile = new Class({
this.callback(this, false);
},
onProgress: function (event)
{
var audio = event.target;
audio.removeEventListener('canplaythrough', this.onProgress);
audio.removeEventListener('error', this.onError);
},
// Called by the Loader, starts the actual file downloading
load: function (callback, baseURL)
{
@ -49,6 +56,8 @@ var HTML5AudioFile = new Class({
var audio = new Audio();
audio.name = this.key;
audio.preload = 'auto';
audio.addEventListener('canplaythrough', this.onProgress, false);
audio.addEventListener('error', this.onProgress, false);
audio.src = GetURL(this, baseURL || '');
audio.load();