diff --git a/src/module/qt_window/mpvwidget.cc b/src/module/qt_window/mpvwidget.cc index e7140409c3a66606989f4faa08fd61e3900e3c49..7917c9b6c91b30593b11add472655fb8f8d5fcc9 100644 --- a/src/module/qt_window/mpvwidget.cc +++ b/src/module/qt_window/mpvwidget.cc @@ -50,6 +50,9 @@ MpvWidget::MpvWidget(queue *queue, lkt_db *db, module_reg *reg, bool *launched, mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); + mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG); + mpv_observe_property(mpv, 0, "unpause", MPV_FORMAT_FLAG); + mpv_observe_property(mpv, 0, "idle-active", MPV_FORMAT_FLAG); mpv_set_wakeup_callback(mpv, wakeup, this); } @@ -130,9 +133,6 @@ MpvWidget::handle_mpv_event(mpv_event *event) (void)prop; switch (event->event_id) { - case MPV_EVENT_PAUSE: lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PAUSE); break; - case MPV_EVENT_UNPAUSE: lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY); break; - case MPV_EVENT_SHUTDOWN: lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_STOP); *m_launched = false; @@ -159,33 +159,63 @@ MpvWidget::handle_mpv_event(mpv_event *event) if (prop->format == MPV_FORMAT_DOUBLE) { m_duration = static_cast<int>(*reinterpret_cast<double *>(prop->data)); } + } else if (strcmp(prop->name, "pause") == 0) { + LOG_DEBUG("WINDOW", "Detected pause"); + if (prop->format == MPV_FORMAT_FLAG) { + if (*static_cast<int*>(prop->data)) + goto apply_pause; + else + goto apply_unpause; + } + } else if (strcmp(prop->name, "unpause") == 0) { + LOG_DEBUG("WINDOW", "Detected unpause"); + if (prop->format == MPV_FORMAT_FLAG) { + if (*static_cast<int*>(prop->data)) + goto apply_unpause; + else + goto apply_pause; + } + } else if (strcmp(prop->name, "idle-active") == 0) { + LOG_DEBUG("WINDOW", "Detected idle"); + if (prop->format == MPV_FORMAT_FLAG && *static_cast<int*>(prop->data)) { + LOG_DEBUG("WINDOW", "Applying idle"); + lkt_queue_make_available(m_queue, static_cast<LKT_EVENT_TYPE>(LKT_EVENT_PLAY)); + lkt_queue_make_available(m_queue, static_cast<LKT_EVENT_TYPE>(LKT_EVENT_PROP)); + *m_launched = true; + emit titleChanged("[Lektord] Stopped"); + } } break; - } - case MPV_EVENT_IDLE: - lkt_queue_make_available(m_queue, static_cast<LKT_EVENT_TYPE>(LKT_EVENT_PLAY)); - lkt_queue_make_available(m_queue, static_cast<LKT_EVENT_TYPE>(LKT_EVENT_PROP)); - *m_launched = true; - emit titleChanged("[Lektord] Stopped"); +apply_pause: + LOG_DEBUG("WINDOW", "Applying pause"); + lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PAUSE); + break; +apply_unpause: + LOG_DEBUG("WINDOW", "Applying unpause"); + lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY); break; + // TODO: deprecated events that are now monitored with observe_property but that we didn't use + // Check if we want to observe them or not + //case MPV_EVENT_TRACKS_CHANGED: + //case MPV_EVENT_TRACK_SWITCHED: + //case MPV_EVENT_TICK: + //case MPV_EVENT_METADATA_UPDATE: + //case MPV_EVENT_CHAPTER_CHANGE: + } + case MPV_EVENT_LOG_MESSAGE: case MPV_EVENT_GET_PROPERTY_REPLY: case MPV_EVENT_SET_PROPERTY_REPLY: case MPV_EVENT_NONE: case MPV_EVENT_COMMAND_REPLY: case MPV_EVENT_FILE_LOADED: - case MPV_EVENT_TRACKS_CHANGED: - case MPV_EVENT_TRACK_SWITCHED: - case MPV_EVENT_TICK: case MPV_EVENT_SCRIPT_INPUT_DISPATCH: case MPV_EVENT_CLIENT_MESSAGE: case MPV_EVENT_VIDEO_RECONFIG: case MPV_EVENT_AUDIO_RECONFIG: - case MPV_EVENT_METADATA_UPDATE: case MPV_EVENT_SEEK: - case MPV_EVENT_CHAPTER_CHANGE: case MPV_EVENT_PLAYBACK_RESTART: case MPV_EVENT_QUEUE_OVERFLOW: case MPV_EVENT_HOOK: break;