From 34175e7cca1de4e79c93a94bde795157815feb4c Mon Sep 17 00:00:00 2001 From: dragonflylee Date: Thu, 16 Nov 2023 22:27:39 +0800 Subject: [PATCH] Move disableDimming to VideoView --- wiliwili/include/view/mpv_core.hpp | 5 --- wiliwili/include/view/video_view.hpp | 5 +++ wiliwili/source/view/mpv_core.cpp | 54 ++++++---------------------- wiliwili/source/view/video_view.cpp | 16 +++++++++ 4 files changed, 31 insertions(+), 49 deletions(-) diff --git a/wiliwili/include/view/mpv_core.hpp b/wiliwili/include/view/mpv_core.hpp index 6a4fc913d..f5d7e46d2 100644 --- a/wiliwili/include/view/mpv_core.hpp +++ b/wiliwili/include/view/mpv_core.hpp @@ -150,11 +150,6 @@ class MPVCore : public brls::Singleton { void showOsdText(const std::string &value, int duration = 2000); - /** - * 禁用系统锁屏 - */ - static void disableDimming(bool disable); - /** * 绘制视频 * diff --git a/wiliwili/include/view/video_view.hpp b/wiliwili/include/view/video_view.hpp index b0bc2e1b5..eeb2940ec 100644 --- a/wiliwili/include/view/video_view.hpp +++ b/wiliwili/include/view/video_view.hpp @@ -276,4 +276,9 @@ class VideoView : public brls::Box { * seeking_range: 相对进度,单位秒 */ void requestSeeking(); + + /** + * 禁用系统锁屏 + */ + static void disableDimming(bool disable); }; diff --git a/wiliwili/source/view/mpv_core.cpp b/wiliwili/source/view/mpv_core.cpp index 47337b9b6..fbe1dd43d 100644 --- a/wiliwili/source/view/mpv_core.cpp +++ b/wiliwili/source/view/mpv_core.cpp @@ -191,7 +191,6 @@ void MPVCore::init() { // set observe properties check_error(mpv_observe_property(mpv, 1, "core-idle", MPV_FORMAT_FLAG)); - check_error(mpv_observe_property(mpv, 2, "eof-reached", MPV_FORMAT_FLAG)); check_error(mpv_observe_property(mpv, 3, "duration", MPV_FORMAT_INT64)); check_error( mpv_observe_property(mpv, 4, "playback-time", MPV_FORMAT_DOUBLE)); @@ -206,7 +205,6 @@ void MPVCore::init() { check_error(mpv_observe_property(mpv, 12, "pause", MPV_FORMAT_FLAG)); check_error( mpv_observe_property(mpv, 13, "playback-abort", MPV_FORMAT_FLAG)); - check_error(mpv_observe_property(mpv, 14, "seeking", MPV_FORMAT_FLAG)); check_error( mpv_observe_property(mpv, 15, "hwdec-current", MPV_FORMAT_STRING)); @@ -657,7 +655,6 @@ void MPVCore::eventMainLoop() { return; case MPV_EVENT_SHUTDOWN: brls::Logger::info("========> MPV_EVENT_SHUTDOWN"); - disableDimming(false); return; case MPV_EVENT_LOG_MESSAGE: { auto log = (mpv_event_log_message *)event->data; @@ -686,11 +683,8 @@ void MPVCore::eventMainLoop() { case MPV_EVENT_START_FILE: // event 6: 开始加载文件 brls::Logger::info("========> MPV_EVENT_START_FILE"); - disableDimming(true); - // show osd for a really long time mpvCoreEvent.fire(MpvEventEnum::START_FILE); - mpvCoreEvent.fire(MpvEventEnum::LOADING_START); break; case MPV_EVENT_PLAYBACK_RESTART: @@ -701,28 +695,31 @@ void MPVCore::eventMainLoop() { if (AUTO_PLAY) { mpvCoreEvent.fire(MpvEventEnum::MPV_RESUME); this->resume(); - disableDimming(true); } else { mpvCoreEvent.fire(MpvEventEnum::MPV_PAUSE); this->pause(); - disableDimming(false); } break; + case MPV_EVENT_SEEK: + brls::Logger::info("========> VIDEO SEEKING"); + mpvCoreEvent.fire(MpvEventEnum::LOADING_START); + break; case MPV_EVENT_END_FILE: { // event 7: 文件播放结束 - disableDimming(false); - brls::Logger::info("========> MPV_STOP"); - mpvCoreEvent.fire(MpvEventEnum::MPV_STOP); video_stopped = true; - disableDimming(false); auto node = (mpv_event_end_file *)event->data; if (node->reason == MPV_END_FILE_REASON_ERROR) { mpv_error_code = node->error; brls::Logger::error("========> MPV ERROR: {}", mpv_error_string(node->error)); mpvCoreEvent.fire(MpvEventEnum::MPV_FILE_ERROR); + } else if (node->reason == MPV_END_FILE_REASON_EOF) { + brls::Logger::info("========> END OF FILE"); + mpvCoreEvent.fire(MpvEventEnum::END_OF_FILE); + } else { + brls::Logger::info("========> MPV_STOP"); + mpvCoreEvent.fire(MpvEventEnum::MPV_STOP); } - break; } case MPV_EVENT_PROPERTY_CHANGE: { @@ -731,14 +728,6 @@ void MPVCore::eventMainLoop() { case 1: if (data) video_playing = *(int *)data == 0; break; - case 2: - if (data) video_eof = *(int *)data; - if (video_eof) { - brls::Logger::info("========> END OF FILE"); - mpvCoreEvent.fire(MpvEventEnum::END_OF_FILE); - disableDimming(false); - } - break; case 3: // 视频总时长更新 if (((mpv_event_property *)event->data)->data) @@ -796,12 +785,10 @@ void MPVCore::eventMainLoop() { brls::Logger::info( "========> VIDEO PAUSED FOR CACHE"); mpvCoreEvent.fire(MpvEventEnum::LOADING_START); - disableDimming(false); } else { brls::Logger::info( "========> VIDEO RESUME FROM CACHE"); mpvCoreEvent.fire(MpvEventEnum::LOADING_END); - disableDimming(true); } break; case 8: @@ -866,24 +853,14 @@ void MPVCore::eventMainLoop() { if (video_paused) { brls::Logger::info("========> PAUSE"); mpvCoreEvent.fire(MpvEventEnum::MPV_PAUSE); - disableDimming(false); } else if (!video_stopped) { brls::Logger::info("========> RESUME"); mpvCoreEvent.fire(MpvEventEnum::MPV_RESUME); - disableDimming(true); } break; case 13: if (data) video_stopped = *(int *)data; - break; - case 14: - if (data) video_seeking = *(int *)data; - if (video_seeking) { - brls::Logger::info("========> VIDEO SEEKING"); - mpvCoreEvent.fire(MpvEventEnum::LOADING_START); - disableDimming(false); - } break; case 15: if (data) { @@ -1014,17 +991,6 @@ std::unordered_map MPVCore::getNodeMap( double MPVCore::getPlaybackTime() const { return playback_time; } -void MPVCore::disableDimming(bool disable) { - brls::Application::getPlatform()->disableScreenDimming( - disable, "Playing video", APPVersion::getPackageName()); - static bool deactivationAvailable = - ProgramConfig::instance().getSettingItem(SettingItem::DEACTIVATED_TIME, - 0) > 0; - if (deactivationAvailable) { - brls::Application::setAutomaticDeactivation(!disable); - } -} - void MPVCore::setShader(const std::string &profile, const std::string &shaders, bool showHint) { brls::Logger::info("Set shader [{}]: {}", profile, shaders); diff --git a/wiliwili/source/view/video_view.cpp b/wiliwili/source/view/video_view.cpp index c2a37dcd3..2ad824873 100644 --- a/wiliwili/source/view/video_view.cpp +++ b/wiliwili/source/view/video_view.cpp @@ -526,10 +526,22 @@ void VideoView::requestSeeking() { }); } +void VideoView::disableDimming(bool disable) { + brls::Application::getPlatform()->disableScreenDimming( + disable, "Playing video", APPVersion::getPackageName()); + static bool deactivationAvailable = + ProgramConfig::instance().getSettingItem(SettingItem::DEACTIVATED_TIME, + 0) > 0; + if (deactivationAvailable) { + brls::Application::setAutomaticDeactivation(!disable); + } +} + VideoView::~VideoView() { brls::Logger::debug("trying delete VideoView..."); this->unRegisterMpvEvent(); MPV_CE->unsubscribe(customEventSubscribeID); + disableDimming(false); brls::Logger::debug("Delete VideoView done"); } @@ -786,10 +798,12 @@ void VideoView::toggleOSD() { void VideoView::showLoading() { centerLabel->setVisibility(brls::Visibility::INVISIBLE); osdCenterBox->setVisibility(brls::Visibility::VISIBLE); + disableDimming(false); } void VideoView::hideLoading() { osdCenterBox->setVisibility(brls::Visibility::GONE); + disableDimming(true); } void VideoView::hideDanmakuButton() { @@ -1152,6 +1166,7 @@ void VideoView::registerMpvEvent() { break; case MpvEventEnum::MPV_PAUSE: this->showOSD(false); + disableDimming(false); refreshToggleIcon(); break; case MpvEventEnum::START_FILE: @@ -1201,6 +1216,7 @@ void VideoView::registerMpvEvent() { case MpvEventEnum::END_OF_FILE: // 播放结束自动取消全屏 this->showOSD(false); + disableDimming(false); this->btnToggleIcon->setImageFromSVGRes( "svg/bpx-svg-sprite-play.svg"); if (EXIT_FULLSCREEN_ON_END && closeOnEndOfFile &&