From 3c16cb376669e4ae500d22529b40112c761088c0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 20 Jul 2021 23:34:30 +0200 Subject: Fix cursor not autohiding sometimes because start of video is not always detected properly --- src/QuickMedia.cpp | 19 +++++++++++++++---- src/VideoPlayer.cpp | 30 +++++++++++++++--------------- src/plugins/Matrix.cpp | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 1ec2c53..723e8ec 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -2531,6 +2531,10 @@ namespace QuickMedia { PageType previous_page = pop_page_stack(); bool video_loaded = false; + bool in_seeking = false; + sf::Clock seeking_start_timer; + const float seeking_restart_timeout_sec = 10.0f; // TODO: Test if this timeout is good on slow hardware such as pinephone and slow internet + std::string youtube_video_id_dummy; const bool is_youtube = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy); const bool is_matrix = strcmp(plugin_name, "matrix") == 0; @@ -2546,10 +2550,19 @@ namespace QuickMedia { } sf::WindowHandle video_player_window = None; - auto on_window_create = [this, &video_player_window](sf::WindowHandle _video_player_window) mutable { + auto on_window_create = [this, &video_player_window, &video_loaded, &in_seeking](sf::WindowHandle _video_player_window) mutable { video_player_window = _video_player_window; XSelectInput(disp, video_player_window, KeyPressMask | PointerMotionMask); XSync(disp, False); + + // Hack to detect video playing if the video starts playing before we have connected to the ipc. + // TODO: This is an issue just because of ubuntu shit that uses old mpv that doesn't support ipc over file descriptors. + double time_in_file = 0.0; + video_player->get_time_in_file(&time_in_file); + if(time_in_file > 0.00001) { + video_loaded = true; + in_seeking = false; + } }; std::unique_ptr youtube_video_media_proxy; @@ -2567,9 +2580,7 @@ namespace QuickMedia { std::string audio_url; bool has_embedded_audio = true; - bool in_seeking = false; - sf::Clock seeking_start_timer; - const float seeking_restart_timeout_sec = 10.0f; // TODO: Test if this timeout is good on slow hardware such as pinephone and slow internet + std::string prev_start_time; std::vector media_chapters; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index d4e27d1..ba7fb81 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -275,6 +275,20 @@ namespace QuickMedia { VideoPlayer::Error VideoPlayer::update() { const int max_retries_find_window = 1000; + if(video_process_id != -1) { + if(wait_program_non_blocking(video_process_id, &exit_status)) { + fprintf(stderr, "The video player exited!, status: %d\n", exit_status); + close(ipc_socket); + remove(ipc_server_path); + ipc_server_path[0] = '\0'; + video_process_id = -1; + ipc_socket = -1; + window_handle = None; + connected_to_ipc = false; + return Error::EXITED; + } + } + if(ipc_socket == -1) return Error::INIT_FAILED; @@ -317,21 +331,7 @@ namespace QuickMedia { } } - if(video_process_id != -1) { - if(wait_program_non_blocking(video_process_id, &exit_status)) { - fprintf(stderr, "The video player exited!, status: %d\n", exit_status); - close(ipc_socket); - remove(ipc_server_path); - ipc_server_path[0] = '\0'; - video_process_id = -1; - ipc_socket = -1; - window_handle = None; - connected_to_ipc = false; - return Error::EXITED; - } - } - - if(connected_to_ipc && event_callback) { + if(connected_to_ipc && window_handle && event_callback) { Error err = read_ipc_func(); if(err != Error::OK) return err; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 7439bf6..4d00949 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -3468,7 +3468,7 @@ namespace QuickMedia { } if((int)file_analyzer.get_file_size() > upload_limit) { - err_msg = "File is too large! max upload size on your homeserver is " + std::to_string(upload_limit) + " bytes, the file you tried to upload is " + std::to_string(file_analyzer.get_file_size()) + " bytes"; + err_msg = "File is too large! max upload size on your homeserver is " + std::to_string((double)upload_limit / 1024.0 / 1024.0) + " mb, the file you tried to upload is " + std::to_string((double)file_analyzer.get_file_size() / 1024.0 / 1024.0) + " mb"; return PluginResult::ERR; } -- cgit v1.2.3