diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 3f85da97a7..871336505c 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -320,6 +320,69 @@ RB_WRAP(playlist_insert_directory) | |||
320 | return 1; | 320 | return 1; |
321 | } | 321 | } |
322 | 322 | ||
323 | RB_WRAP(audio) | ||
324 | { | ||
325 | enum e_audio {AUDIO_STATUS = 0, AUDIO_PLAY, AUDIO_STOP, AUDIO_PAUSE, | ||
326 | AUDIO_RESUME, AUDIO_NEXT, AUDIO_PREV, AUDIO_FFREWIND, | ||
327 | AUDIO_FLUSHANDRELOADTRACKS, AUDIO_GETPOS, AUDIO_ECOUNT}; | ||
328 | const char *audio_option[] = {"status", "play", "stop", "pause", | ||
329 | "resume", "next", "prev", "ffrewind", | ||
330 | "flushandreloadtracks", "getfilepos", NULL}; | ||
331 | long elapsed, offset, newtime; | ||
332 | int status = rb->audio_status(); | ||
333 | |||
334 | int option = luaL_checkoption (L, 1, NULL, audio_option); | ||
335 | switch(option) | ||
336 | { | ||
337 | default: | ||
338 | case AUDIO_STATUS: | ||
339 | break; | ||
340 | case AUDIO_PLAY: | ||
341 | elapsed = luaL_checkint(L, 2); | ||
342 | offset = luaL_checkint(L, 3); | ||
343 | |||
344 | if (status == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE)) | ||
345 | { | ||
346 | /* not perfect but provides a decent compromise */ | ||
347 | rb->audio_ff_rewind(elapsed + offset); | ||
348 | rb->audio_resume(); | ||
349 | } | ||
350 | else if (status != AUDIO_STATUS_PLAY) | ||
351 | rb->audio_play((unsigned long) elapsed, (unsigned long) offset); | ||
352 | |||
353 | break; | ||
354 | case AUDIO_STOP: | ||
355 | rb->audio_stop(); | ||
356 | break; | ||
357 | case AUDIO_PAUSE: | ||
358 | rb->audio_pause(); | ||
359 | break; | ||
360 | case AUDIO_RESUME: | ||
361 | rb->audio_resume(); | ||
362 | break; | ||
363 | case AUDIO_NEXT: | ||
364 | rb->audio_next(); | ||
365 | break; | ||
366 | case AUDIO_PREV: | ||
367 | rb->audio_prev(); | ||
368 | break; | ||
369 | case AUDIO_FFREWIND: | ||
370 | newtime = (long) luaL_checkint(L, 2); | ||
371 | rb->audio_ff_rewind(newtime); | ||
372 | break; | ||
373 | case AUDIO_FLUSHANDRELOADTRACKS: | ||
374 | rb->audio_flush_and_reload_tracks(); | ||
375 | break; | ||
376 | case AUDIO_GETPOS: | ||
377 | lua_pushinteger(L, rb->audio_get_file_pos()); | ||
378 | return 1; | ||
379 | } | ||
380 | |||
381 | rb->yield(); | ||
382 | lua_pushinteger(L, status); /* return previous (or current) audio status */ | ||
383 | return 1; | ||
384 | } | ||
385 | |||
323 | SIMPLE_VOID_WRAPPER(backlight_force_on); | 386 | SIMPLE_VOID_WRAPPER(backlight_force_on); |
324 | SIMPLE_VOID_WRAPPER(backlight_use_settings); | 387 | SIMPLE_VOID_WRAPPER(backlight_use_settings); |
325 | 388 | ||
@@ -449,6 +512,8 @@ static const luaL_Reg rocklib[] = | |||
449 | RB_FUNC(strip_extension), | 512 | RB_FUNC(strip_extension), |
450 | RB_FUNC(create_numbered_filename), | 513 | RB_FUNC(create_numbered_filename), |
451 | 514 | ||
515 | RB_FUNC(audio), | ||
516 | |||
452 | {NULL, NULL} | 517 | {NULL, NULL} |
453 | }; | 518 | }; |
454 | #undef RB_FUNC | 519 | #undef RB_FUNC |