File: test_sdl_audio_mix_playing.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (42 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <SDL/SDL_mixer.h>
#include <emscripten.h>

Mix_Chunk* chunk = 0;
uint64_t started = 0;

void loop() {
  uint64_t now = emscripten_get_now();
  if (now - started > 2000) {
    // length of sound is 1sec
    printf("isPlaying? %s\n", Mix_Playing(0) ? "yes" : "no");
    emscripten_force_exit(Mix_Playing(0) ? 1 : 0);
  }
}

int main(int argc, char** argv) {
  if ((Mix_Init(MIX_INIT_OGG) & MIX_INIT_OGG) != MIX_INIT_OGG) {
    printf("ERR! Mix_Init: Failed to init with required flags support!\n");
    printf("ERR! Mix_Init: %s\n", Mix_GetError());
    return 1;
  }

  if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 1, 1024) == -1) {
    printf("ERR! Mix_OpenAudio: %s\n", Mix_GetError());
    return 1;
  }

  Mix_AllocateChannels(1);
  chunk = Mix_LoadWAV("/noise.ogg");
  if (!chunk) {
    printf("ERR! Mix_LoadWAV: %s\n", Mix_GetError());
    return 1;
  }
  Mix_PlayChannel(0, chunk, 0);
  if (!Mix_Playing(0)) {
    printf("ERR! Channel is not playing\n");
    return 1;
  }
  started = emscripten_get_now();
  emscripten_set_main_loop(loop, 0, 0);
  return 0;
}