aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Bishop <mbtyke@gmail.com>2013-02-21 23:46:44 -0500
committerMichael J. Bishop <mbtyke@gmail.com>2013-02-22 10:47:23 -0500
commita7d7dad8baefd2fae9f56ab46afe7af7fef215cd (patch)
tree4ddfeadc8de0da003b9dbc5c8fae63465c9b4af0
parent122a07dd4f399b8985fafedf4e515b8484b17c3c (diff)
Added some SDL_Mixer calls:
- `Mix_Playing` - `Mix_Pause` - `Mix_Pause` - `Mix_Resume`
-rw-r--r--src/library_sdl.js62
-rw-r--r--tests/sdl_audio.c20
2 files changed, 78 insertions, 4 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index e02e1e62..1cb41071 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1434,10 +1434,72 @@ var LibrarySDL = {
return (SDL.music.audio && !SDL.music.audio.paused) ? 1 : 0;
},
+ // http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_38.html#SEC38
+ // "Note: Does not check if the channel has been paused."
+ Mix_Playing: function(id) {
+ if (id === -1)
+ {
+ var count = 0;
+ for (var i = 0; i<SDL.audios.length;i++)
+ count += SDL.Mix_Playing(i);
+ return count;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio && !info.audio.playing)
+ return 1;
+ return 0;
+ },
+
+ Mix_Pause: function(id) {
+ if (id === -1)
+ {
+ for (var i = 0; i<SDL.audios.length;i++)
+ SDL.Mix_Pause(i);
+ return;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio)
+ {
+ console.log("paused " + id);
+ info.audio.pause();
+ }
+ },
+
+ // http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_39.html#SEC39
+ Mix_Paused: function(id) {
+ if (id === -1)
+ {
+ var pausedCount = 0;
+ for (var i = 0; i<SDL.audios.length;i++)
+ pausedCount += SDL.Mix_Paused(i);
+ return pausedCount;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio && info.audio.paused)
+ return 1;
+ return 0;
+ },
+
Mix_PausedMusic: function() {
return (SDL.music.audio && SDL.music.audio.paused) ? 1 : 0;
},
+ // http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_33.html#SEC33
+ Mix_Resume: function(id) {
+ if (id === -1)
+ {
+ for (var i = 0; i<SDL.audios.length;i++)
+ SDL.Mix_Resume(i);
+ return;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio)
+ {
+ console.log("resumed " + id);
+ info.audio.play();
+ }
+ },
+
// SDL TTF
TTF_Init: function() { return 0 },
diff --git a/tests/sdl_audio.c b/tests/sdl_audio.c
index 938df3c4..ce3bf5a9 100644
--- a/tests/sdl_audio.c
+++ b/tests/sdl_audio.c
@@ -6,13 +6,14 @@
Mix_Chunk *sound, *sound2;
-void play2();
+int play2();
-void play() {
+int play() {
int channel = Mix_PlayChannel(-1, sound, 1);
assert(channel == 0);
emscripten_run_script("setTimeout(Module['_play2'], 500)");
+ return channel;
}
void done(int channel) {
@@ -22,11 +23,12 @@ void done(int channel) {
REPORT_RESULT();
}
-void play2() {
+int play2() {
Mix_ChannelFinished(done);
int channel2 = Mix_PlayChannel(-1, sound2, 1);
assert(channel2 == 1);
+ return channel2;
}
int main(int argc, char **argv) {
@@ -40,7 +42,17 @@ int main(int argc, char **argv) {
sound2 = Mix_LoadWAV("sound2.wav");
assert(sound);
- play();
+ int channel = play();
+ printf( "Pausing Channel %d", channel );
+ Mix_Pause(channel);
+ int paused = Mix_Paused(channel);
+ printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
+ assert(paused);
+ Mix_Resume(channel);
+ paused = Mix_Paused(channel);
+ printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
+ assert(paused == 0);
+
if (argc == 12121) play2(); // keep it alive
emscripten_run_script("element = document.createElement('input');"