+static void play (struct afb_req request) { /* AFB_SESSION_CHECK */
+
+ audioCtxHandleT *ctx = afb_req_context_get (request);
+ const char *value = afb_req_value (request, "value");
+ json_object *jresp;
+
+ if (!ctx) {
+ afb_req_fail (request, "failed", "you must call 'init' first");
+ return;
+ }
+ jresp = json_object_new_object();
+
+ /* no "?value=" parameter : return current state */
+ if (!value) {
+ ctx->is_playing ?
+ json_object_object_add (jresp, "play", json_object_new_string ("on"))
+ : json_object_object_add (jresp, "play", json_object_new_string ("off"));
+ afb_req_success (request, jresp, "Audio - Playing status obtained");
+ return;
+ }
+
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
+ ctx->is_playing = 1;
+ _backend_play (ctx);
+ json_object_object_add (jresp, "play", json_object_new_string ("on"));
+ }
+
+ /* "?value=" parameter is "0" or "false" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) {
+ ctx->is_playing = 0;
+ _backend_stop (ctx);
+ json_object_object_add (jresp, "play", json_object_new_string ("off"));
+ }
+
+ afb_req_success (request, jresp, "Audio - Play");