2#include "AudioTools/CoreAudio/AudioPlayer.h"
18 void setOutput(
Print &out) { p_out = &out; }
20 bool setActive(
bool active) {
return active ? play() : stop(); }
23 if (p_out ==
nullptr)
return false;
26 OSCData msg{data,
sizeof(data)};
30 p_out->write(msg.data(), msg.size());
36 if (p_out ==
nullptr)
return false;
38 OSCData msg{data,
sizeof(data)};
42 p_out->write(msg.data(), msg.size());
48 bool next(
int offset = 1) {
49 if (p_out ==
nullptr)
return false;
51 OSCData msg{data,
sizeof(data)};
55 msg.write((int32_t)offset);
56 p_out->write(msg.data(), msg.size());
60 bool previous(
int offset = 1) {
61 if (p_out ==
nullptr)
return false;
63 OSCData msg{data,
sizeof(data)};
67 msg.write((int32_t)offset);
68 p_out->write(msg.data(), msg.size());
73 bool setIndex(
int idx) {
74 if (p_out ==
nullptr)
return false;
76 OSCData msg{data,
sizeof(data)};
80 msg.write((int32_t)idx);
81 p_out->write(msg.data(), msg.size());
86 bool setPath(
const char *path) {
87 if (p_out ==
nullptr)
return false;
88 uint8_t data[strlen(path) + 20];
89 OSCData msg{data,
sizeof(data)};
94 p_out->write(msg.data(), msg.size());
98 bool setVolume(
float volume) {
99 if (p_out ==
nullptr)
return false;
101 OSCData msg{data,
sizeof(data)};
106 p_out->write(msg.data(), msg.size());
111 Print *p_out =
nullptr;
125 setAudioPlayer(player);
128 void setAudioPlayer(
AudioPlayer &player) { p_player = &player; }
131 bool processInputMessage(
Stream &in) {
132 if (!is_active)
return false;
135 size_t len = in.readBytes(data,
sizeof(data));
137 if (osc.
parse(data, len)) {
146 if (p_player ==
nullptr) {
147 LOGE(
"RCAudioPlayerOSCReceiver: player is null");
163 bool is_active =
false;
166 static bool play(
OSCData &data,
void *ref) {
178 static bool next(
OSCData &data,
void *ref) {
181 return p_player->
next(offset);
184 static bool previous(
OSCData &data,
void *ref) {
189 static bool setIndex(
OSCData &data,
void *ref) {
194 static bool setPath(
OSCData &data,
void *ref) {
197 return p_player->
setPath(path);
199 static bool setVolume(
OSCData &data,
void *ref) {
205 void registerCallbacks() {
206 osc.
addCallback(
"/play", play, OSCCompare::StartsWith);
208 osc.
addCallback(
"/next", next, OSCCompare::StartsWith);
209 osc.
addCallback(
"/previous", previous, OSCCompare::StartsWith);
210 osc.
addCallback(
"/index", setIndex, OSCCompare::StartsWith);
211 osc.
addCallback(
"/path", setPath, OSCCompare::StartsWith);
212 osc.
addCallback(
"/volume", setVolume, OSCCompare::StartsWith);
void stop()
Public generic methods.
Definition AudioRuntime.h:14