From b18051c16b4ab7384fdb0fc8dc3453d7b1c6208d Mon Sep 17 00:00:00 2001 From: xfangfang <2553041586@qq.com> Date: Fri, 15 Dec 2023 02:56:07 +0800 Subject: [PATCH] VideoView: show replay button when end of file --- resources/svg/bpx-svg-sprite-re-play.svg | 1 + wiliwili/include/view/mpv_core.hpp | 1 + wiliwili/include/view/video_view.hpp | 3 +++ .../source/activity/player_base_activity.cpp | 21 ++++++++------- wiliwili/source/view/mpv_core.cpp | 7 ++++- wiliwili/source/view/video_view.cpp | 26 ++++++++++++++----- 6 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 resources/svg/bpx-svg-sprite-re-play.svg diff --git a/resources/svg/bpx-svg-sprite-re-play.svg b/resources/svg/bpx-svg-sprite-re-play.svg new file mode 100644 index 00000000..4c2f0b89 --- /dev/null +++ b/resources/svg/bpx-svg-sprite-re-play.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wiliwili/include/view/mpv_core.hpp b/wiliwili/include/view/mpv_core.hpp index 375392d3..8db8b2ec 100644 --- a/wiliwili/include/view/mpv_core.hpp +++ b/wiliwili/include/view/mpv_core.hpp @@ -51,6 +51,7 @@ typedef enum MpvEventEnum { MPV_LOADED, MPV_PAUSE, MPV_RESUME, + MPV_IDLE, MPV_STOP, MPV_FILE_ERROR, LOADING_START, diff --git a/wiliwili/include/view/video_view.hpp b/wiliwili/include/view/video_view.hpp index bb230e1e..57d4dcc6 100644 --- a/wiliwili/include/view/video_view.hpp +++ b/wiliwili/include/view/video_view.hpp @@ -202,6 +202,7 @@ class VideoView : public brls::Box { inline static const std::string SET_QUALITY = "SET_QUALITY"; inline static const std::string HINT = "HINT"; inline static const std::string LAST_TIME = "LAST_TIME"; + inline static const std::string REPLAY = "REPLAY"; // 用于指定 lastPlayedPosition 的值 // 若无历史记录,则为 -1,若不使用历史记录的值,则为 -2 @@ -235,6 +236,8 @@ class VideoView : public brls::Box { bool showHighlightLineSetting = true; // 是否为直播样式 bool isLiveMode = false; + // 是否展示重播按钮 + bool showReplay = false; MPVEvent::Subscription eventSubscribeID; MPVCustomEvent::Subscription customEventSubscribeID; std::function customToggleAction = nullptr; diff --git a/wiliwili/source/activity/player_base_activity.cpp b/wiliwili/source/activity/player_base_activity.cpp index 54a5abc7..cd27ace6 100644 --- a/wiliwili/source/activity/player_base_activity.cpp +++ b/wiliwili/source/activity/player_base_activity.cpp @@ -73,7 +73,7 @@ class DataSourceCommentList : public RecyclingGridDataSource, // 回复评论 brls::Application::getImeManager()->openForText( [this, recycler](const std::string& text) { - if (text.empty()) return ; + if (text.empty()) return; this->commentReply( text, aid, 0, 0, [this, recycler]( @@ -355,15 +355,18 @@ void BasePlayerActivity::setCommonData() { } auto stack = brls::Application::getActivitiesStack(); Activity* top = stack[stack.size() - 1]; - if (!dynamic_cast(top)) { - // 判断最顶层是否为video - if (!dynamic_cast( - top->getContentView()->getView("video"))) - return; - } - if (PLAYER_STRATEGY == PlayerStrategy::NEXT || - PLAYER_STRATEGY == PlayerStrategy::RCMD) { + if (!dynamic_cast(top) && + !dynamic_cast( + top->getContentView()->getView("video"))) { + // 最顶层没有 video 组件,说明用户打开了评论或者其他菜单 + // 在这种情况下不执行自动播放其他视频显示重播按钮 + MPV_CE->fire(VideoView::REPLAY, nullptr); + } else if (PLAYER_STRATEGY == PlayerStrategy::NEXT || + PLAYER_STRATEGY == PlayerStrategy::RCMD) { this->onIndexChangeToNext(); + } else { + // 对于其他情况,显示重播按钮 + MPV_CE->fire(VideoView::REPLAY, nullptr); } } break; diff --git a/wiliwili/source/view/mpv_core.cpp b/wiliwili/source/view/mpv_core.cpp index 65c76365..e63aac67 100644 --- a/wiliwili/source/view/mpv_core.cpp +++ b/wiliwili/source/view/mpv_core.cpp @@ -809,7 +809,12 @@ void MPVCore::eventMainLoop() { switch (event->reply_userdata) { case 1: if (data) { - video_playing = *(int *)data == 0; + bool playing = *(int *)data == 0; + if (playing != video_playing){ + video_playing = playing; + mpvCoreEvent.fire(MpvEventEnum::MPV_IDLE); + } + video_playing = playing; disableDimming(video_playing); } break; diff --git a/wiliwili/source/view/video_view.cpp b/wiliwili/source/view/video_view.cpp index 96b5c6ba..df98b174 100644 --- a/wiliwili/source/view/video_view.cpp +++ b/wiliwili/source/view/video_view.cpp @@ -528,6 +528,10 @@ VideoView::VideoView() { this->setLastPlayedPosition(*(int64_t*)data / 1000); } else if (event == VideoView::HINT) { this->showHint((const char*)data); + } else if (event == VideoView::REPLAY) { + // 显示重播按钮 + showReplay = true; + this->refreshToggleIcon(); } }); } @@ -812,7 +816,11 @@ void VideoView::stop() { mpvCore->stop(); } void VideoView::togglePlay() { if (customToggleAction != nullptr) return customToggleAction(); if (this->mpvCore->isPaused()) { - this->mpvCore->resume(); + if (showReplay) { + this->mpvCore->seek(0); + } else { + this->mpvCore->resume(); + } } else { this->mpvCore->pause(); } @@ -1028,7 +1036,11 @@ void VideoView::refreshDanmakuIcon() { } void VideoView::refreshToggleIcon() { - if (mpvCore->isPaused() || mpvCore->isStopped()) { + if (!mpvCore->isPlaying()) { + if (showReplay) { + btnToggleIcon->setImageFromSVGRes("svg/bpx-svg-sprite-re-play.svg"); + return; + } btnToggleIcon->setImageFromSVGRes("svg/bpx-svg-sprite-play.svg"); } else { btnToggleIcon->setImageFromSVGRes("svg/bpx-svg-sprite-pause.svg"); @@ -1103,6 +1115,7 @@ void VideoView::setFullScreen(bool fs) { video->showOSD(this->osd_state != OSDState::ALWAYS_ON); video->setFullscreenIcon(true); video->setHideHighlight(true); + video->showReplay = showReplay; video->refreshToggleIcon(); video->setHighlightProgress(highlight_step_sec, highlight_data); if (video->isLiveMode) video->setLiveMode(); @@ -1153,6 +1166,7 @@ void VideoView::setFullScreen(bool fs) { video->setPlaybackTime( this->leftStatusLabel->getFullText()); video->registerMpvEvent(); + video->showReplay = showReplay; video->refreshToggleIcon(); video->refreshDanmakuIcon(); video->setQuality(this->getQuality()); @@ -1287,14 +1301,16 @@ void VideoView::registerMpvEvent() { mpvCore->getEvent()->subscribe([this](MpvEventEnum event) { // brls::Logger::info("mpv event => : {}", event); switch (event) { + case MpvEventEnum::MPV_IDLE: + refreshToggleIcon(); + break; case MpvEventEnum::MPV_RESUME: + this->showReplay = false; this->showOSD(true); this->hideLoading(); - refreshToggleIcon(); break; case MpvEventEnum::MPV_PAUSE: this->showOSD(false); - refreshToggleIcon(); break; case MpvEventEnum::START_FILE: this->showOSD(false); @@ -1343,8 +1359,6 @@ void VideoView::registerMpvEvent() { case MpvEventEnum::END_OF_FILE: // 播放结束自动取消全屏 this->showOSD(false); - this->btnToggleIcon->setImageFromSVGRes( - "svg/bpx-svg-sprite-play.svg"); if (EXIT_FULLSCREEN_ON_END && closeOnEndOfFile && this->isFullscreen()) { this->setFullScreen(false);