diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index d294f4a1339516bec53c10e894da02e2de0e5078..66d351f5d9337038a9e87e90e2742b16b83f32a6 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -440,6 +440,7 @@ module_sdl2_close(struct module_sdl2_window *win) { RETURN_UNLESS(win && win->window, "Invalid arguments", NOTHING); win->mpv_time_pos = win->mpv_duration = 0; + win->state = STATE_STOP; RETURN_UNLESS(win->mpv, "Missing mpv ctx", NOTHING); static const char *cmd[] = { "stop", NULL }; mpv_command_async((mpv_handle *) win->mpv, 0, cmd); diff --git a/src/module/mpv.c b/src/module/mpv.c index 5b955b4adf66b60d94c3b3d6190e05c73f974622..67735f98e43f94a29cb4ed877be4f1451960be6e 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -10,12 +10,6 @@ #include <unistd.h> #include <sqlite3.h> -enum { - STATE_STOP = 0, - STATE_PLAY = 1, - STATE_PAUSE = 2, -}; - void lmpv_free(mpv_handle **ctx) { @@ -151,8 +145,7 @@ lmpv_toggle_pause(mpv_handle *ctx) int lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, - volatile int *time_pos, volatile int *time_duration, - volatile int *state) + volatile int *time_pos, volatile int *time_duration, volatile int *state) { size_t ao_volume; mpv_event *event = NULL; @@ -183,8 +176,13 @@ loop: case MPV_EVENT_NONE: return 1; - case MPV_EVENT_IDLE: - if (*state != STATE_STOP && *time_pos > 0) + case MPV_EVENT_START_FILE: + LOG_DEBUG("WINDOW", "Start of file!"); + break; + + case MPV_EVENT_END_FILE: + LOG_DEBUG("WINDOW", "End of file!"); + if ((*state) != STATE_STOP) lkt_queue_send(queue, lkt_event_play_next, NULL); break; @@ -222,15 +220,22 @@ loop: } break; + case MPV_EVENT_COMMAND_REPLY: + free((void *) event->reply_userdata); + break; + /* Ignored */ case MPV_EVENT_VIDEO_RECONFIG: case MPV_EVENT_AUDIO_RECONFIG: + case MPV_EVENT_IDLE: + case MPV_EVENT_TRACKS_CHANGED: + case MPV_EVENT_FILE_LOADED: + case MPV_EVENT_METADATA_UPDATE: + case MPV_EVENT_PLAYBACK_RESTART: break; - case MPV_EVENT_COMMAND_REPLY: - free((void *) event->reply_userdata); - break; - + /* Forgot to ignore an event, or it should not be ignored and should be + * handled, or a new event is present in the API */ default: LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); break; diff --git a/src/module/mpv.h b/src/module/mpv.h index cff2cc186318b1f680618659c3f8838fd5cdac06..d6901e8df88a82ca5102d749d5d162f6651cb213 100644 --- a/src/module/mpv.h +++ b/src/module/mpv.h @@ -15,5 +15,11 @@ int lmpv_set_volume(mpv_handle *ctx, int vol); int lmpv_load_file(mpv_handle *ctx, const char *file); int lmpv_toggle_pause(mpv_handle *ctx); int lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, - volatile int *time_pos, volatile int *time_duration, - volatile int *state); + volatile int *time_pos, volatile int *time_duration, volatile int *state); + +enum { + STATE_STOP = 0, + STATE_PLAY = 1, + STATE_PAUSE = 2, +}; +