diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-17 16:56:11 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-17 16:56:11 +0200 |
commit | db8f15fe4ea1686023584fcebd218a9c5e354caf (patch) | |
tree | 334e3be8bbfe766906e3d18525df6315e30d5bad | |
parent | ceb1a46b665440c45b97071a8b233ff44275ddaf (diff) |
Fix possible freeze in video player when closing it, or it moving to the next video when closing it
-rw-r--r-- | include/VideoPlayer.hpp | 1 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 3 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 30 |
3 files changed, 23 insertions, 11 deletions
diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index 79de8cd..bea03fc 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -78,6 +78,7 @@ namespace QuickMedia { Error send_command(Json::Value &json_root, Json::Value *result, Json::ValueType result_type); Error launch_video_process(); VideoPlayer::Error read_ipc_func(); + void check_if_exited(); private: StartupArgs startup_args; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index ac236b4..151c136 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3738,6 +3738,7 @@ namespace QuickMedia { } else { current_page = previous_page; go_to_previous_page = true; + break; } } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::Q) { current_page = previous_page; @@ -3906,7 +3907,7 @@ namespace QuickMedia { current_page = previous_page; go_to_previous_page = true; break; - } else if(update_err == VideoPlayer::Error::EXITED && video_player->exit_status == 0 && (!is_matrix || is_youtube)) { + } else if(update_err == VideoPlayer::Error::EXITED && video_player->exit_status == 0 && (!is_matrix || is_youtube) && !go_to_previous_page) { std::string new_video_url; if(!video_page->should_autoplay()) { diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 1049bcf..c56981a 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -343,16 +343,9 @@ 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); - video_process_id = -1; - ipc_socket = -1; - window_handle = None; - return Error::EXITED; - } - } + check_if_exited(); + if(video_process_id == -1) + return Error::EXITED; if(ipc_socket == -1) return Error::INIT_FAILED; @@ -413,6 +406,10 @@ namespace QuickMedia { std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader()); std::string json_errors; + check_if_exited(); + if(video_process_id == -1) + return Error::EXITED; + char buffer[2048]; ssize_t bytes_read = read_eintr(ipc_socket, buffer, sizeof(buffer)); if(bytes_read == -1) { @@ -461,6 +458,19 @@ namespace QuickMedia { return Error::OK; } + void VideoPlayer::check_if_exited() { + if(video_process_id == -1) + return; + + if(wait_program_non_blocking(video_process_id, &exit_status)) { + fprintf(stderr, "The video player exited!, status: %d\n", exit_status); + close(ipc_socket); + video_process_id = -1; + ipc_socket = -1; + window_handle = None; + } + } + VideoPlayer::Error VideoPlayer::get_time_in_file(double *result_seconds) { Json::Value json_root(Json::objectValue); json_root["command"] = "time-pos"; |