diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2013-03-14 19:57:23 -0400 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-15 11:53:16 -0700 |
commit | ff46d95e04588f0d328ef8c49b12ebaa99a782a0 (patch) | |
tree | b789ffa49feff14d52518fa88682e9d3990a75ce | |
parent | be5bc3b617c7cca563f3b1cfe4ab3a5083318e67 (diff) |
Add tests for playback states
-rw-r--r-- | src/library_openal.js | 6 | ||||
-rw-r--r-- | tests/openal_playback.cpp | 32 |
2 files changed, 34 insertions, 4 deletions
diff --git a/src/library_openal.js b/src/library_openal.js index 2166a712..992b2557 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -288,7 +288,8 @@ var LibraryOpenAL = { src.buffer = AL.currentContext.src[source - 1].buffer; src.connect(AL.currentContext.src[source - 1].gain); src.start(0, offset); - AL.currentContext.src[source - 1].playTime = AL.currentContext.ctx.currentTime; + // Work around Firefox bug 851338 + AL.currentContext.src[source - 1].playTime = AL.currentContext.ctx.currentTime || 0; AL.currentContext.src[source - 1].paused = false; AL.currentContext.src[source - 1]['src'] = src; }, @@ -320,7 +321,8 @@ var LibraryOpenAL = { 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; + // Work around Firefox bug 851338 + AL.currentContext.src[source - 1].pausedTime = AL.currentContext.ctx.currentTime || 0; AL.currentContext.src[source - 1]["src"].stop(0); delete AL.currentContext.src[source - 1].src; } diff --git a/tests/openal_playback.cpp b/tests/openal_playback.cpp index 4afa55fb..13d619e6 100644 --- a/tests/openal_playback.cpp +++ b/tests/openal_playback.cpp @@ -2,6 +2,28 @@ #include <stdlib.h> #include <AL/al.h> #include <AL/alc.h> +#include <assert.h> +#include <emscripten.h> + +void playSource(void* arg) +{ + ALuint source = reinterpret_cast<ALuint>(arg); + ALint state; + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + alSourcePause(source); + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PAUSED); + alSourcePlay(source); + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + alSourceStop(source); + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_STOPPED); + + int result = 1; + REPORT_RESULT(); +} int main() { ALCdevice* device = alcOpenDevice(NULL); @@ -78,10 +100,16 @@ int main() { alSourcei(sources[0], AL_BUFFER, buffers[0]); + ALint state; + alGetSourcei(sources[0], AL_SOURCE_STATE, &state); + assert(state == AL_INITIAL); + alSourcePlay(sources[0]); - int result = 1; - REPORT_RESULT(); + alGetSourcei(sources[0], AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + + emscripten_async_call(playSource, reinterpret_cast<void*>(sources[0]), 700); return 0; } |