Skip to content

Commit

Permalink
VideoView: show replay button when end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Dec 14, 2023
1 parent 2b3f77a commit b18051c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions resources/svg/bpx-svg-sprite-re-play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef enum MpvEventEnum {
MPV_LOADED,
MPV_PAUSE,
MPV_RESUME,
MPV_IDLE,
MPV_STOP,
MPV_FILE_ERROR,
LOADING_START,
Expand Down
3 changes: 3 additions & 0 deletions wiliwili/include/view/video_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<void()> customToggleAction = nullptr;
Expand Down
21 changes: 12 additions & 9 deletions wiliwili/source/activity/player_base_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down Expand Up @@ -355,15 +355,18 @@ void BasePlayerActivity::setCommonData() {
}
auto stack = brls::Application::getActivitiesStack();
Activity* top = stack[stack.size() - 1];
if (!dynamic_cast<BasePlayerActivity*>(top)) {
// 判断最顶层是否为video
if (!dynamic_cast<VideoView*>(
top->getContentView()->getView("video")))
return;
}
if (PLAYER_STRATEGY == PlayerStrategy::NEXT ||
PLAYER_STRATEGY == PlayerStrategy::RCMD) {
if (!dynamic_cast<BasePlayerActivity*>(top) &&
!dynamic_cast<VideoView*>(
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;
Expand Down
7 changes: 6 additions & 1 deletion wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 20 additions & 6 deletions wiliwili/source/view/video_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b18051c

Please sign in to comment.