Skip to content

Commit

Permalink
Settings: Add an option: "Auto-play on video detail page"
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Oct 18, 2024
1 parent 5d36db3 commit cc5c9c2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions resources/i18n/en-US/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"low_quality": "Low quality decoding (with less CPU usage)",
"in_memory_cache": "Inmemory cache",
"hwdec": "Hardware decode",
"auto_play": "Auto-play on video detail page",
"exit_fullscreen": "Exit full screen at the end of playback",
"play_strategy": "Play strategy",
"auto_play_next_part": "Automatically playing next part",
Expand Down Expand Up @@ -83,6 +84,7 @@
"opencc": "Automatically convert Simplified Chinese (restart required)",
"keymap": {
"header": "Keymap style",
"swap": "Swap AB/XY",
"xbox": "Xbox",
"ps": "PlayStation",
"keyboard": "Keyboard"
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/zh-Hans/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"low_quality": "低画质解码(以画质为代价换取更低的功耗)",
"in_memory_cache": "解码缓存",
"hwdec": "硬件解码",
"auto_play": "视频详情页直接播放",
"exit_fullscreen": "播放结束时自动退出全屏",
"play_strategy": "播放方式",
"auto_play_next_part": "自动播放分集",
Expand Down Expand Up @@ -83,6 +84,7 @@
"opencc": "自动转换简体中文 (需要重启)",
"keymap": {
"header": "键位图标 (需要重启)",
"swap": "键位交换",
"xbox": "Xbox",
"ps": "PlayStation",
"keyboard": "键盘"
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/zh-Hant/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"low_quality": "低畫質解碼(以畫質為代價換取更低的功耗)",
"in_memory_cache": "解码緩存",
"hwdec": "硬體解碼",
"auto_play": "影片詳細頁直接播放",
"exit_fullscreen": "播放結束時自動退出全屏",
"play_strategy": "播放方式",
"auto_play_next_part": "自動播放分集",
Expand Down Expand Up @@ -83,6 +84,7 @@
"opencc": "自動轉換簡體中文 (需要重啓)",
"keymap": {
"header": "鍵位風格 (需要重啟)",
"swap": "鍵位交換",
"xbox": "Xbox",
"ps": "PlayStation",
"keyboard": "鍵盤"
Expand Down
6 changes: 6 additions & 0 deletions resources/xml/activity/setting_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<brls:BooleanCell
id="setting/video/hwdec"/>

<brls:BooleanCell
id="setting/video/auto_play"/>

<SelectorCell
id="setting/video/inmemory"/>

Expand Down Expand Up @@ -133,6 +136,9 @@
<SelectorCell
id="setting/keymap"/>

<brls:BooleanCell
id="setting/keymap_swap"/>

<SelectorCell
id="setting/ui/theme"/>
</brls:Box>
Expand Down
2 changes: 2 additions & 0 deletions wiliwili/include/activity/setting_activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class SettingActivity : public brls::Activity {
BRLS_BIND(BiliSelectorCell, selectorTexture, "setting/image/texture");
BRLS_BIND(BiliSelectorCell, selectorThreads, "setting/image/threads");
BRLS_BIND(BiliSelectorCell, selectorKeymap, "setting/keymap");
BRLS_BIND(brls::BooleanCell, btnKeymapSwap, "setting/keymap_swap");
BRLS_BIND(brls::BooleanCell, btnOpencc, "setting/opencc");
BRLS_BIND(brls::BooleanCell, btnQuality, "setting/video/quality");
BRLS_BIND(brls::BooleanCell, btnHWDEC, "setting/video/hwdec");
BRLS_BIND(brls::BooleanCell, btnAutoPlay, "setting/video/auto_play");
BRLS_BIND(BiliSelectorCell, selectorInmemory, "setting/video/inmemory");
BRLS_BIND(BiliSelectorCell, selectorFormat, "setting/video/format");
BRLS_BIND(BiliSelectorCell, selectorCodec, "setting/video/codec");
Expand Down
1 change: 1 addition & 0 deletions wiliwili/include/utils/config_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class SettingItem {
APP_SWAP_ABXY, // A-B 交换 和 X-Y 交换
SCROLL_SPEED, // 列表滑动速度
HISTORY_REPORT,
PLAYER_AUTO_PLAY, // 进入详情页自动播放
PLAYER_STRATEGY,
PLAYER_BOTTOM_BAR,
PLAYER_HIGHLIGHT_BAR,
Expand Down
16 changes: 15 additions & 1 deletion wiliwili/source/activity/setting_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void SettingActivity::onContentAvailable() {
brls::Application::getPlatform()->getVideoContext()->fullScreen(value);
});

auto setOnTopCell = [this](bool enabled){
auto setOnTopCell = [this](bool enabled) {
if (enabled) {
cellOnTopMode->setDetailTextColor(brls::Application::getTheme()["brls/list/listItem_value_color"]);
} else {
Expand Down Expand Up @@ -481,6 +481,13 @@ void SettingActivity::onContentAvailable() {
selectorKeymap->setVisibility(brls::Visibility::GONE);
#endif

/// Swap ABXY
btnKeymapSwap->init("wiliwili/setting/app/others/keymap/swap"_i18n, conf.getBoolOption(SettingItem::APP_SWAP_ABXY),
[](bool data) {
ProgramConfig::instance().setSettingItem(SettingItem::APP_SWAP_ABXY, data);
brls::Application::setSwapInputKeys(data);
});

/// App language
static int langIndex = conf.getStringOptionIndex(SettingItem::APP_LANG);
selectorLang->init("wiliwili/setting/app/others/language/header"_i18n,
Expand Down Expand Up @@ -648,6 +655,13 @@ void SettingActivity::onContentAvailable() {
});
#endif

/// Auto Play when open video detail page
btnAutoPlay->init("wiliwili/setting/app/playback/auto_play"_i18n, conf.getBoolOption(SettingItem::PLAYER_AUTO_PLAY),
[](bool value) {
ProgramConfig::instance().setSettingItem(SettingItem::PLAYER_AUTO_PLAY, value);
MPVCore::AUTO_PLAY = value;
});

/// Decode quality
btnQuality->init("wiliwili/setting/app/playback/low_quality"_i18n,
conf.getBoolOption(SettingItem::PLAYER_LOW_QUALITY), [](bool value) {
Expand Down
3 changes: 2 additions & 1 deletion wiliwili/source/utils/config_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ std::unordered_map<SettingItem, ProgramOption> ProgramConfig::SETTING_MAP = {
{SettingItem::FULLSCREEN, {"fullscreen", {}, {}, 1}},
#endif
{SettingItem::HISTORY_REPORT, {"history_report", {}, {}, 1}},
{SettingItem::PLAYER_AUTO_PLAY, {"player_auto_play", {}, {}, 1}},
{SettingItem::PLAYER_BOTTOM_BAR, {"player_bottom_bar", {}, {}, 1}},
{SettingItem::PLAYER_HIGHLIGHT_BAR, {"player_highlight_bar", {}, {}, 0}},
{SettingItem::PLAYER_SKIP_OPENING_CREDITS, {"player_skip_opening_credits", {}, {}, 1}},
Expand Down Expand Up @@ -480,7 +481,7 @@ void ProgramConfig::load() {
}

// 加载完成后自动播放
MPVCore::AUTO_PLAY = true;
MPVCore::AUTO_PLAY = getBoolOption(SettingItem::PLAYER_AUTO_PLAY);

// 初始化默认的倍速设定
MPVCore::VIDEO_SPEED = getIntOption(SettingItem::PLAYER_DEFAULT_SPEED);
Expand Down
16 changes: 9 additions & 7 deletions wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ void MPVCore::init() {
sleepTime = std::chrono::system_clock::now();
pause();
// do not automatically play video
autoPlay = AUTO_PLAY;
AUTO_PLAY = false;
}
});
Expand Down Expand Up @@ -847,6 +848,14 @@ void MPVCore::eventMainLoop() {
mpvCoreEvent.fire(MpvEventEnum::UPDATE_PROGRESS);
// 移除其他备用链接
command_async("playlist-clear");

if (AUTO_PLAY) {
mpvCoreEvent.fire(MpvEventEnum::MPV_RESUME);
this->resume();
} else {
mpvCoreEvent.fire(MpvEventEnum::MPV_PAUSE);
this->pause();
}
break;
case MPV_EVENT_START_FILE:
// event 6: 开始加载文件
Expand All @@ -862,13 +871,6 @@ void MPVCore::eventMainLoop() {
brls::Logger::info("========> MPV_EVENT_PLAYBACK_RESTART");
video_stopped = false;
mpvCoreEvent.fire(MpvEventEnum::LOADING_END);
if (AUTO_PLAY) {
mpvCoreEvent.fire(MpvEventEnum::MPV_RESUME);
this->resume();
} else {
mpvCoreEvent.fire(MpvEventEnum::MPV_PAUSE);
this->pause();
}
break;
case MPV_EVENT_END_FILE: {
// event 7: 文件播放结束
Expand Down

0 comments on commit cc5c9c2

Please sign in to comment.