aboutsummaryrefslogtreecommitdiff
path: root/src/library_openal.js
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2013-03-14 19:15:27 -0400
committerAlon Zakai <alonzakai@gmail.com>2013-03-15 11:53:16 -0700
commit00a39d2658d7c473274d15ff4bd159f018a78d38 (patch)
tree028ac7ea131c1d2698e3ff1a8df3ff29d3b26803 /src/library_openal.js
parent837404f6fe65b058aad7ec618adf0deda5159216 (diff)
Implement proper pause/replay support
Diffstat (limited to 'src/library_openal.js')
-rw-r--r--src/library_openal.js39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/library_openal.js b/src/library_openal.js
index ef88ce3f..e6400a29 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -86,7 +86,15 @@ var LibraryOpenAL = {
gain.connect(AL.currentContext.ctx.destination);
}
gain.gain.value = 1; // work around a Firefox bug (bug 850970)
- AL.currentContext.src.push({loop: false, buffer: null, gain: gain, panner: panner});
+ AL.currentContext.src.push({
+ loop: false,
+ buffer: null,
+ gain: gain,
+ panner: panner,
+ paused: false,
+ playTime: 0,
+ pausedTime: 0
+ });
{{{ makeSetValue('sources', 'i', 'AL.currentContext.src.length', 'i32') }}};
}
},
@@ -265,16 +273,23 @@ var LibraryOpenAL = {
console.error("alSourcePlay called with an invalid source");
return;
}
+ var offset = 0;
if ("src" in AL.currentContext.src[source - 1]) {
// If the source is already playing, we need to resume from beginning.
// We do that by stopping the current source and replaying it.
_alSourceStop(source);
+ } else if (AL.currentContext.src[source - 1].paused) {
+ // So now we have to resume playback, remember the offset here.
+ offset = AL.currentContext.src[source - 1].pausedTime -
+ AL.currentContext.src[source - 1].playTime;
}
var src = AL.currentContext.ctx.createBufferSource();
src.loop = AL.currentContext.src[source - 1].loop;
src.buffer = AL.currentContext.src[source - 1].buffer;
src.connect(AL.currentContext.src[source - 1].gain);
- src.start(0);
+ src.start(0, offset);
+ AL.currentContext.src[source - 1].playTime = AL.currentContext.ctx.currentTime;
+ AL.currentContext.src[source - 1].paused = false;
AL.currentContext.src[source - 1]['src'] = src;
},
@@ -288,7 +303,25 @@ var LibraryOpenAL = {
return;
}
if ("src" in AL.currentContext.src[source - 1]) {
- AL.currentContext.src[source - 1].src.stop(0);
+ AL.currentContext.src[source - 1]["src"].stop(0);
+ delete AL.currentContext.src[source - 1]["src"];
+ }
+ },
+
+ alSourcePause: function(source) {
+ if (!AL.currentContext) {
+ console.error("alSourcePause called without a valid context");
+ return;
+ }
+ if (source > AL.currentContext.src.length) {
+ console.error("alSourcePause called with an invalid source");
+ return;
+ }
+ if ("src" in AL.currentContext.src[source - 1] &&
+ !AL.currentContext.src[source - 1].paused) {
+ AL.currentContext.src[source - 1].paused = true;
+ AL.currentContext.src[source - 1].pausedTime = AL.currentContext.ctx.currentTime;
+ AL.currentContext.src[source - 1]["src"].stop(0);
delete AL.currentContext.src[source - 1].src;
}
},