aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp82
1 files changed, 57 insertions, 25 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 4b441ec..3e41899 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3232,6 +3232,44 @@ namespace QuickMedia {
std::string audio_url;
bool has_embedded_audio = true;
+ auto update_video_duration_handler = [&]() {
+ if(!video_player)
+ return;
+
+ if(update_duration) {
+ update_duration = false;
+ successfully_fetched_video_duration = true;
+ double file_duration = 0.0;
+ video_player->get_duration_in_file(&file_duration);
+ video_info.duration = std::max(video_info.duration, file_duration);
+ if(video_info.duration > 0.001)//
+ successfully_fetched_video_duration = true;//
+ }
+ };
+
+ auto update_time_pos_handler = [&](bool force) {
+ if(!video_player)
+ return;
+
+ if(force) {
+ video_time_pos_clock.restart();
+ update_time_pos = true;
+ }
+
+ if(video_time_pos_clock.get_elapsed_time_seconds() >= 5.0) {
+ video_time_pos_clock.restart();
+ update_time_pos = true;
+ }
+
+ if(update_time_pos) {
+ update_time_pos = false;
+ if(video_player->get_time_in_file(&video_time_pos) == VideoPlayer::Error::OK)
+ successfully_fetched_time_pos = true;
+ }
+
+ update_video_duration_handler();
+ };
+
auto load_video_error_check = [&](std::string start_time = "", bool reuse_media_source = false) mutable {
video_player.reset();
video_info.channel_url.clear();
@@ -3240,6 +3278,9 @@ namespace QuickMedia {
successfully_fetched_time_pos = false;
video_player_window = None;
video_info.duration = 0.0;
+ video_time_pos_clock.restart();
+ update_time_pos = false;
+ video_time_pos = 0.0;
bool is_audio_only = no_video;
const int video_max_height = video_get_max_height();
@@ -3346,6 +3387,8 @@ namespace QuickMedia {
const bool is_resume_go_back = !start_time.empty();
if(start_time.empty())
start_time = video_page->get_url_timestamp();
+
+ fprintf(stderr, "start time: %s\n", start_time.c_str());
watched_videos.insert(video_page->get_url());
// TODO: Sync sequences
@@ -3456,6 +3499,9 @@ namespace QuickMedia {
update_time_pos = true;
} else if(strcmp(event_name, "fullscreen") == 0 && args.size() == 1) {
window_set_fullscreen(disp, window.get_system_handle(), args[0] == "yes" ? WindowFullscreenState::SET : WindowFullscreenState::UNSET);
+ } else if(strcmp(event_name, "end-file") == 0) {
+ if(successfully_fetched_time_pos && successfully_fetched_video_duration)
+ video_page->set_watch_progress(video_time_pos, video_info.duration);
}
//fprintf(stderr, "event name: %s\n", event_name);
@@ -3494,7 +3540,7 @@ namespace QuickMedia {
} else if(event.type == mgl::Event::Resized) {
window_size.x = event.size.width;
window_size.y = event.size.height;
- } else if(event.type == mgl::Event::KeyPressed && (event.key.code == mgl::Keyboard::Escape || event.key.code == mgl::Keyboard::Q || event.key.code == mgl::Keyboard::Backspace)) {
+ } else if(event.type == mgl::Event::KeyPressed && (event.key.code == mgl::Keyboard::Escape || event.key.code == mgl::Keyboard::Backspace)) {
// To be able to close the video player while the video is loading
if(window_is_fullscreen(disp, window.get_system_handle())) {
if(video_player && video_player_window && event.key.code != mgl::Keyboard::Escape)
@@ -3503,6 +3549,9 @@ namespace QuickMedia {
current_page = previous_page;
go_to_previous_page = true;
}
+ } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::Q) {
+ current_page = previous_page;
+ go_to_previous_page = true;
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::C && event.key.control && !video_page->is_local()) {
save_video_url_to_clipboard();
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F5 && !video_page->is_local()) {
@@ -3538,8 +3587,10 @@ namespace QuickMedia {
KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0);
#pragma GCC diagnostic pop
bool pressing_ctrl = (CLEANMASK(xev.xkey.state) == ControlMask);
- if(pressed_keysym == XK_q && pressing_ctrl) {
- window.close();
+ if(pressed_keysym == XK_q) {
+ current_page = previous_page;
+ go_to_previous_page = true;
+ break;
} else if(pressed_keysym == XK_Escape || pressed_keysym == XK_q || pressed_keysym == XK_BackSpace) {
if(window_is_fullscreen(disp, window.get_system_handle())) {
if(pressed_keysym != XK_Escape)
@@ -3600,6 +3651,7 @@ namespace QuickMedia {
show_video_player_window(video_player_window);
show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL);
} else if(related_pages_result == TaskResult::TRUE && !related_pages.empty()) {
+ update_time_pos_handler(true);
if(successfully_fetched_time_pos && successfully_fetched_video_duration)
video_page->set_watch_progress(video_time_pos, video_info.duration);
@@ -3776,28 +3828,8 @@ namespace QuickMedia {
continue;
}
- if(video_player) {
- if(video_time_pos_clock.get_elapsed_time_seconds() >= 5.0) {
- video_time_pos_clock.restart();
- update_time_pos = true;
- }
-
- if(update_time_pos) {
- update_time_pos = false;
- if(video_player->get_time_in_file(&video_time_pos) == VideoPlayer::Error::OK)
- successfully_fetched_time_pos = true;
- }
-
- if(update_duration) {
- update_duration = false;
- successfully_fetched_video_duration = true;
- double file_duration = 0.0;
- video_player->get_duration_in_file(&file_duration);
- video_info.duration = std::max(video_info.duration, file_duration);
- if(video_info.duration > 0.001)
- successfully_fetched_video_duration = true;
- }
- }
+ if(video_player)
+ update_time_pos_handler(false);
if(video_player_window) {
if(!cursor_visible) {