An enumeration of audio device states.
SDL_AUDIO_STOPPED |
audio device is stopped |
SDL_AUDIO_PLAYING |
audio device is playing |
SDL_AUDIO_PAUSED |
audio device is paused |
void printStatus(SDL_AudioDeviceID dev)
{switch (SDL_GetAudioDeviceStatus(dev))
{case SDL_AUDIO_STOPPED: printf("stopped\n"); break;
case SDL_AUDIO_PLAYING: printf("playing\n"); break;
case SDL_AUDIO_PAUSED: printf("paused\n"); break;
default: printf("???"); break;
}
}
// device starts paused
SDL_AudioDeviceID dev;
SDL_AudioSpec desired;
SDL_AudioSpec obtained;extern void SDLCALL audio_callback(void *userdata, Uint8 * stream, int len);
SDL_zero(desired);44100;
desired.freq =
desired.format = AUDIO_F32SYS;1;
desired.channels = 4096;
desired.samples =
desired.callback = audio_callback;0, &desired, &obtained, 0);
dev = SDL_OpenAudioDevice(NULL, if (dev != 0)
{// prints "paused"
printStatus(dev); 0);
SDL_PauseAudioDevice(dev, // prints "playing"
printStatus(dev); 1);
SDL_PauseAudioDevice(dev, // prints "paused"
printStatus(dev);
SDL_CloseAudioDevice(dev);// prints "stopped"
printStatus(dev); }
Opened devices are always PLAYING or PAUSED in normal circumstances. A failing device may change its status to STOPPED at any time, and closing a device will progress to STOPPED, too. Asking for the state on an unopened or unknown device ID will report STOPPED.