Skip to content

Commit

Permalink
Move disableDimming to VideoView
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed Nov 16, 2023
1 parent 960c043 commit 34175e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 49 deletions.
5 changes: 0 additions & 5 deletions wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ class MPVCore : public brls::Singleton<MPVCore> {

void showOsdText(const std::string &value, int duration = 2000);

/**
* 禁用系统锁屏
*/
static void disableDimming(bool disable);

/**
* 绘制视频
*
Expand Down
5 changes: 5 additions & 0 deletions wiliwili/include/view/video_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,9 @@ class VideoView : public brls::Box {
* seeking_range: 相对进度,单位秒
*/
void requestSeeking();

/**
* 禁用系统锁屏
*/
static void disableDimming(bool disable);
};
54 changes: 10 additions & 44 deletions wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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: {
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1014,17 +991,6 @@ std::unordered_map<std::string, mpv_node> 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);
Expand Down
16 changes: 16 additions & 0 deletions wiliwili/source/view/video_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -1152,6 +1166,7 @@ void VideoView::registerMpvEvent() {
break;
case MpvEventEnum::MPV_PAUSE:
this->showOSD(false);
disableDimming(false);
refreshToggleIcon();
break;
case MpvEventEnum::START_FILE:
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit 34175e7

Please sign in to comment.