]> 105106.c2e0p.group Git - sound.git/blobdiff - sound.js
Add timeupdate support.
[sound.git] / sound.js
index a2601533f3b23be3bf38dcb0035886c80ca40072..e195ca69041689b36b098d8cd066465b6c0db333 100644 (file)
--- a/sound.js
+++ b/sound.js
@@ -45,6 +45,7 @@ function Sound(src) {
 
     this.selectResourceTimer = null;
     this.fetchResourceTimer = null;
+    this.timeUpdateTimer = null;
 
     this.buffer = null;
     this.node = null;
@@ -270,8 +271,13 @@ Sound.prototype = {
         this.node.playbackRate.value = this._playbackRate;
         this.node.start(0, this.nextStartTime);
         this.node.onended = this.onended.bind(this);
+
+        this.timeUpdateTimer = setInterval(this.sendTimeUpdate.bind(this), 250);
     },
 
+    sendTimeUpdate: function() {
+        this.dispatchEventAsync(new CustomEvent('timeupdate'));
+    },
 
     pause: function() {
         if (this._networkState === this.NETWORK.EMPTY)
@@ -301,6 +307,8 @@ Sound.prototype = {
             this.gainNode.disconnect();
             delete this.gainNode;
         }
+
+        clearInterval(this.timeUpdateTimer);
     },
 
     onended: function() {