#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
void onSoundBegin(uint16_t id, float volume)
{
spdlog::info("Sound begin id:{}, volume:{:.2f}", id, volume);
}
void onSoundComplete(uint16_t id)
{
spdlog::info("Sound complete id:{}", id);
}
void onSoundAbort(uint16_t id)
{
spdlog::info("Sound aborted id:{}", id);
}
void onSoundError(uint16_t id)
{
spdlog::error("Sound error id:{}", id);
}
int main()
{
spdlog::set_level(spdlog::level::info);
spdlog::flush_on(spdlog::level::trace);
spdlog::error("Doly service stop failed");
return -1;
}
{
spdlog::error("SoundControl init failed");
return -2;
}
if (ret < 0)
spdlog::error("Play failed, error code:{}", ret);
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}
Shared helper utilities and common types used across the Doly SDK.
Public API for Doly sound playback control.
@ STOP
Definition SoundControl.h:31
int8_t stopDolyService()
Stop the background Doly service (if running).
int8_t setVolume(uint8_t volume)
Set playback volume as a percentage.
SoundState getState()
Get current sound playback state.
float getVersion()
Get current library version.
int8_t dispose()
Dispose/stop the sound subsystem and release resources.
int8_t init()
Initialize sound control.
int8_t play(std::string file_name, uint16_t id)
Start playing a sound file (non-blocking).
void AddListenerOnError(void(*onAbort)(uint16_t id))
Register a static/free function to receive error events.
void AddListenerOnAbort(void(*onAbort)(uint16_t id))
Register a static/free function to receive abort events.
void RemoveListenerOnError(void(*onAbort)(uint16_t id))
Unregister a previously registered error callback.
void AddListenerOnComplete(void(*onComplete)(uint16_t id))
Register a static/free function to receive completion events.
void AddListenerOnBegin(void(*onComplete)(uint16_t id, float volume))
Register a static/free function to receive begin events.
void RemoveListenerOnBegin(void(*onComplete)(uint16_t id, float volume))
Unregister a previously registered begin callback.
void RemoveListenerOnComplete(void(*onComplete)(uint16_t id))
Unregister a previously registered completion callback.
void RemoveListenerOnAbort(void(*onAbort)(uint16_t id))
Unregister a previously registered abort callback.