Skip to content

Commit

Permalink
Made autoplay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
windows-server-2003 committed Nov 26, 2021
1 parent c5ccb1c commit de9359a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern bool var_flash_mode;
extern bool var_wifi_enabled;
extern bool var_high_resolution_mode;
extern bool var_history_enabled;
extern int var_autoplay_level;
extern int var_network_framework;
extern int var_network_framework_changed;
extern bool var_show_fps;
Expand Down
1 change: 1 addition & 0 deletions include/youtube_parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct YouTubeVideoDetail {
for (auto suggestion : suggestions) if (suggestion.type == YouTubeSuccinctItem::VIDEO) return true;
return false;
}
bool has_next_video_in_playlist() const { return playlist.videos.size() && playlist.selected_index != (int) playlist.videos.size() - 1; }
YouTubeVideoSuccinct get_next_video() const {
if (playlist.videos.size() && playlist.selected_index != (int) playlist.videos.size() - 1) return playlist.videos[std::max(0, playlist.selected_index + 1)];
for (auto suggestion : suggestions) if (suggestion.type == YouTubeSuccinctItem::VIDEO) return suggestion.video;
Expand Down
2 changes: 2 additions & 0 deletions romfs/gfx/msg/string_resources_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
<FULL_SCREEN_MODE>Full screen mode</FULL_SCREEN_MODE>
<DARK_THEME>Dark theme</DARK_THEME>
<FLASH>Flash</FLASH>
<AUTOPLAY>Autoplay</AUTOPLAY>
<ONLY_IN_PLAYLIST>Playlist only</ONLY_IN_PLAYLIST>
<COMMUNITY_POST_IMAGE_SIZE>Size of images in community posts</COMMUNITY_POST_IMAGE_SIZE>
<LINEAR_FILTER>Linear video filter</LINEAR_FILTER>
<NETWORK_FRAMEWORK>Network framework</NETWORK_FRAMEWORK>
Expand Down
2 changes: 2 additions & 0 deletions romfs/gfx/msg/string_resources_ja.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
<FULL_SCREEN_MODE>フルスクリーンモード</FULL_SCREEN_MODE>
<DARK_THEME>ダークモード</DARK_THEME>
<FLASH>点滅</FLASH>
<AUTOPLAY>自動再生</AUTOPLAY>
<ONLY_IN_PLAYLIST>リスト中でのみ</ONLY_IN_PLAYLIST>
<COMMUNITY_POST_IMAGE_SIZE>コミュニティ投稿の添付画像の大きさ</COMMUNITY_POST_IMAGE_SIZE>
<LINEAR_FILTER>動画の線形フィルタ</LINEAR_FILTER>
<NETWORK_FRAMEWORK>通信フレームワーク</NETWORK_FRAMEWORK>
Expand Down
23 changes: 21 additions & 2 deletions source/scenes/setting_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,25 @@ void Sem_init(void) {
->set_on_release([] (const BarView &view) { misc_tasks_request(TASK_SAVE_SETTINGS); }),
(new EmptyView(0, 0, 320, 10))
}),
// Tab #2 : Data
// Tab #2 : UI/Display
(new ScrollView(0, 0, 320, 0))
->set_views({
// Autoplay
(new SelectorView(0, 0, 320, 35))
->set_texts({
(std::function<std::string ()>) []() { return LOCALIZED(OFF); },
(std::function<std::string ()>) []() { return LOCALIZED(ONLY_IN_PLAYLIST); },
(std::function<std::string ()>) []() { return LOCALIZED(ON); }
}, var_autoplay_level)
->set_title([](const SelectorView &) { return LOCALIZED(AUTOPLAY); })
->set_on_change([](const SelectorView &view) {
if (var_autoplay_level != view.selected_button) {
var_autoplay_level = view.selected_button;
misc_tasks_request(TASK_CHANGE_BRIGHTNESS);
}
}),
}),
// Tab #3 : Data
(new ScrollView(0, 0, 320, 0))
->set_views({
// History recording
Expand Down Expand Up @@ -221,7 +239,7 @@ void Sem_init(void) {
}),
(new EmptyView(0, 0, 320, 10))
}),
// Tab #3 : Advanced
// Tab #4 : Advanced
(new ScrollView(0, 0, 320, 0))
->set_views({
// Eco mode
Expand Down Expand Up @@ -282,6 +300,7 @@ void Sem_init(void) {
}, 0)
->set_tab_texts({
(std::function<std::string ()>) [] () { return LOCALIZED(SETTINGS_DISPLAY_UI); },
(std::function<std::string ()>) [] () { return LOCALIZED(PLAYBACK); },
(std::function<std::string ()>) [] () { return LOCALIZED(SETTINGS_DATA); },
(std::function<std::string ()>) [] () { return LOCALIZED(SETTINGS_ADVANCED); }
});
Expand Down
4 changes: 3 additions & 1 deletion source/scenes/video_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,9 @@ static void decode_thread(void* arg) {
vid_pausing = true;
if (!eof_reached) { // the first time it reaches EOF
svcWaitSynchronization(small_resource_lock, std::numeric_limits<s64>::max());
if (playing_video_info.has_next_video()) send_change_video_request_wo_lock(playing_video_info.get_next_video().url, true, false, false);
if ((var_autoplay_level == 2 && playing_video_info.has_next_video()) ||
(var_autoplay_level == 1 && playing_video_info.has_next_video_in_playlist()))
send_change_video_request_wo_lock(playing_video_info.get_next_video().url, true, false, false);
svcReleaseMutex(small_resource_lock);
}
eof_reached = true;
Expand Down
2 changes: 2 additions & 0 deletions source/system/util/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void load_settings() {
var_night_mode = load_int("dark_theme", 0);
var_flash_mode = load_int("dark_theme_flash", 0);
var_community_image_size = std::min(COMMUNITY_IMAGE_SIZE_MAX, std::max(COMMUNITY_IMAGE_SIZE_MIN, load_int("community_image_size", COMMUNITY_IMAGE_SIZE_DEFAULT)));
var_autoplay_level = std::min(2, std::max(0, load_int("autoplay_level", 2)));
var_network_framework = var_network_framework_changed = load_int("use_experimental_sslc", -1); // for back compability
if (var_network_framework < 0 || var_network_framework >= 3) var_network_framework = var_network_framework_changed = load_int("network_framework", -1);
if (var_network_framework < 0 || var_network_framework >= 3) var_network_framework = var_network_framework_changed = 2;
Expand All @@ -60,6 +61,7 @@ void save_settings() {
"<dark_theme>" + std::to_string(var_night_mode) + "</dark_theme>\n" +
"<dark_theme_flash>" + std::to_string(var_flash_mode) + "</dark_theme_flash>\n" +
"<community_image_size>" + std::to_string(var_community_image_size) + "</community_image_size>\n" +
"<autoplay_level>" + std::to_string(var_autoplay_level) + "</autoplay_level>\n" +
"<network_framework>" + std::to_string(var_network_framework_changed) + "</network_framework>\n" +
"<history_enabled>" + std::to_string(var_history_enabled) + "</history_enabled>\n" +
"<video_show_debug_info>" + std::to_string(var_video_show_debug_info) + "</video_show_debug_info>\n" +
Expand Down
1 change: 1 addition & 0 deletions source/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bool var_flash_mode = false;
bool var_wifi_enabled = false;
bool var_high_resolution_mode = true;
bool var_history_enabled = true;
int var_autoplay_level = 2; // 0 : never, 1 : only in a playlist, 2 : always
int var_network_framework = 1;
int var_network_framework_changed = 1;
bool var_show_fps = false;
Expand Down
1 change: 1 addition & 0 deletions source/youtube_parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct YouTubeVideoDetail {
for (auto suggestion : suggestions) if (suggestion.type == YouTubeSuccinctItem::VIDEO) return true;
return false;
}
bool has_next_video_in_playlist() const { return playlist.videos.size() && playlist.selected_index != (int) playlist.videos.size() - 1; }
YouTubeVideoSuccinct get_next_video() const {
if (playlist.videos.size() && playlist.selected_index != (int) playlist.videos.size() - 1) return playlist.videos[std::max(0, playlist.selected_index + 1)];
for (auto suggestion : suggestions) if (suggestion.type == YouTubeSuccinctItem::VIDEO) return suggestion.video;
Expand Down

0 comments on commit de9359a

Please sign in to comment.