Skip to content

Commit

Permalink
MPV: If stay in the background for too long, it will not automaticall…
Browse files Browse the repository at this point in the history
…y resume.
  • Loading branch information
xfangfang committed Dec 10, 2023
1 parent f9bec3d commit 2392e7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions resources/xml/fragment/mine_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
margin="10"
image="@res/pictures/default_avatar.png"/>
<brls:Box
marginLeft="30"
marginLeft="10"
axis="column"
width="35%">
<brls:Label
Expand All @@ -38,7 +38,7 @@
text=""/>
</brls:Box>
<brls:Box
marginRight="75"
marginRight="10"
alignItems="center"
grow="1">
<brls:Box
Expand Down
7 changes: 5 additions & 2 deletions wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,21 @@ void MPVCore::init() {
brls::Application::getWindowFocusChangedEvent()->subscribe(
[this](bool focus) {
static bool playing = false;
static std::chrono::system_clock::time_point sleepTime{};
// save current AUTO_PLAY value to autoPlay
static bool autoPlay = AUTO_PLAY;
if (focus) {
// restore AUTO_PLAY
AUTO_PLAY = autoPlay;
// application is on top
if (playing) {
auto timeNow = std::chrono::system_clock::now();
if (playing && timeNow < (sleepTime + std::chrono::seconds(120))) {
resume();
}
} else {
// application is sleep, save the current state
playing = !isPaused();
playing = isPlaying();
sleepTime = std::chrono::system_clock::now();
pause();
// do not automatically play video
AUTO_PLAY = false;
Expand Down

0 comments on commit 2392e7a

Please sign in to comment.