From 88fed1806e56181a9161c20bcd93cd06d52a5533 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 Dec 2020 08:18:24 +0100 Subject: Attempt to fix spastic body when using embedded items and loading them in render callback, fix gif play next on 4chan.. test --- src/QuickMedia.cpp | 95 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 42 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 89ced4a..9a47420 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1696,9 +1696,15 @@ namespace QuickMedia { XSync(disp, False); }; - auto load_video_error_check = [this, &related_videos, &channel_url, &video_url, &video_title, &video_player, previous_page, &time_watched_timer, &video_loaded, &added_recommendations, video_page]() mutable { + bool has_video_started = true; + bool end_of_file = false; + std::function video_event_callback; + + auto load_video_error_check = [this, &related_videos, &channel_url, &video_url, &video_title, &video_player, previous_page, &time_watched_timer, &video_loaded, &end_of_file, &added_recommendations, video_page, &video_event_callback, &on_window_create, &video_player_window]() mutable { time_watched_timer.restart(); video_loaded = false; + end_of_file = false; + video_player_window = None; added_recommendations = false; watched_videos.insert(video_url); std::string video_url_converted; @@ -1708,6 +1714,8 @@ namespace QuickMedia { } else { video_url_converted = video_url; } + + video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, false, video_event_callback, on_window_create, resources_root); VideoPlayer::Error err = video_player->load_video(video_url_converted.c_str(), window.getSystemHandle(), plugin_name); if(err != VideoPlayer::Error::OK) { std::string err_msg = "Failed to play url: "; @@ -1755,53 +1763,32 @@ namespace QuickMedia { } }; - bool has_video_started = true; - auto video_event_callback = [this, &related_videos, &video_url, &video_title, &video_player, &load_video_error_check, previous_page, &has_video_started, &time_watched_timer, &video_loaded](const char *event_name) mutable { - bool end_of_file = false; + video_event_callback = [this, &related_videos, &video_url, &video_title, &video_player, &load_video_error_check, previous_page, &has_video_started, &end_of_file, &time_watched_timer, &video_loaded](const char *event_name) mutable { if(strcmp(event_name, "pause") == 0) { - double time_remaining = 9999.0; - if(video_player->get_time_remaining(&time_remaining) == VideoPlayer::Error::OK && time_remaining <= 1.0) - end_of_file = true; + //double time_remaining = 9999.0; + //if(video_player->get_time_remaining(&time_remaining) == VideoPlayer::Error::OK && time_remaining <= 1.0) + // end_of_file = true; } else if(strcmp(event_name, "playback-restart") == 0) { - video_player->set_paused(false); + //video_player->set_paused(false); } else if(strcmp(event_name, "file-loaded") == 0) { has_video_started = true; time_watched_timer.restart(); if(!video_loaded) video_player->set_property("no-resume-playback", true); video_loaded = true; - } else if(strcmp(event_name, "end-file") == 0) { + } else if(strcmp(event_name, "video-reconfig") == 0 || strcmp(event_name, "audio-reconfig") == 0) { + if(!video_loaded) { + video_loaded = true; + time_watched_timer.restart(); + } + } else if(strcmp(event_name, "end-file") == 0 && current_page == PageType::VIDEO_CONTENT) { video_loaded = false; + end_of_file = true; } - if(end_of_file && has_video_started) { - has_video_started = false; - std::string new_video_url; - std::string new_video_title; - // Find video that hasn't been played before in this video session - // TODO: Remove duplicates - for(auto it = related_videos.begin(), end = related_videos.end(); it != end; ++it) { - if(watched_videos.find((*it)->url) == watched_videos.end()) { - new_video_url = (*it)->url; - new_video_title = (*it)->get_title(); - break; - } - } - - // If there are no videos to play, then dont play any... - if(new_video_url.empty()) { - show_notification("QuickMedia", "No more related videos to play"); - current_page = previous_page; - return; - } - - video_url = std::move(new_video_url); - video_title = std::move(new_video_title); - load_video_error_check(); - } + fprintf(stderr, "event name: %s\n", event_name); }; - video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, false, video_event_callback, on_window_create, resources_root); load_video_error_check(); sf::Event event; @@ -1848,8 +1835,9 @@ 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_Escape) { + if(pressed_keysym == XK_Escape || pressed_keysym == XK_BackSpace || pressed_keysym == XK_q) { current_page = previous_page; + break; } else if(pressed_keysym == XK_f && pressing_ctrl) { window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE); } else if(pressed_keysym == XK_r && pressing_ctrl) { @@ -1898,7 +1886,7 @@ namespace QuickMedia { current_page = PageType::VIDEO_CONTENT; video_player_window = None; has_video_started = true; - video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, true, video_event_callback, on_window_create, resources_root); + //video_player = std::make_unique(use_tor, no_video, use_system_mpv_config, true, video_event_callback, on_window_create, resources_root); load_video_error_check(); } else { XMapWindow(disp, video_player_window); @@ -1924,9 +1912,29 @@ namespace QuickMedia { current_page = previous_page; break; } else if(update_err == VideoPlayer::Error::EXITED && video_player->exit_status == 0) { - fprintf(stderr, "mpv exited with status 0, the user most likely closed mpv with 'q'\n"); - current_page = previous_page; - break; + has_video_started = false; + std::string new_video_url; + std::string new_video_title; + // Find video that hasn't been played before in this video session + // TODO: Remove duplicates + for(auto it = related_videos.begin(), end = related_videos.end(); it != end; ++it) { + if(watched_videos.find((*it)->url) == watched_videos.end()) { + new_video_url = (*it)->url; + new_video_title = (*it)->get_title(); + break; + } + } + + // If there are no videos to play, then dont play any... + if(new_video_url.empty()) { + show_notification("QuickMedia", "No more related videos to play"); + current_page = previous_page; + break; + } + + video_url = std::move(new_video_url); + video_title = std::move(new_video_title); + load_video_error_check(); } else if(update_err != VideoPlayer::Error::OK) { show_notification("QuickMedia", "Failed to play the video (error code " + std::to_string((int)update_err) + ")", Urgency::CRITICAL); current_page = previous_page; @@ -3665,6 +3673,7 @@ namespace QuickMedia { body_item->set_description_color(sf::Color(255, 100, 100)); body_item->embedded_item = std::make_shared(""); *body_item->embedded_item = *related_body_item; + body_item->reactions.clear(); body_item->embedded_item_status = FetchStatus::FINISHED_LOADING; return; } @@ -3690,6 +3699,7 @@ namespace QuickMedia { if(related_body_item->userdata && static_cast(related_body_item->userdata)->user == me) body_item->set_description_color(sf::Color(255, 100, 100)); *body_item = *related_body_item; + body_item->reactions.clear(); event_data->status = FetchStatus::FINISHED_LOADING; event_data->message = static_cast(related_body_item->userdata); body_item->userdata = event_data; @@ -3743,6 +3753,7 @@ namespace QuickMedia { body_item->set_description_color(sf::Color(255, 100, 100)); body_item->embedded_item = std::make_shared(""); *body_item->embedded_item = *related_body_item; + body_item->reactions.clear(); body_item->embedded_item_status = FetchStatus::FINISHED_LOADING; return; } @@ -3778,7 +3789,7 @@ namespace QuickMedia { auto fetch_more_previous_messages_if_needed = [this, &tabs, ¤t_room, &fetched_enough_messages, &previous_messages_future]() { if(!fetched_enough_messages && !previous_messages_future.valid()) { - if(!tabs[MESSAGES_TAB_INDEX].body->is_body_full_with_items()) { + if(tabs[MESSAGES_TAB_INDEX].body->items.size() < 30) { previous_messages_future = [this, ¤t_room]() { Messages messages; if(matrix->get_previous_room_messages(current_room, messages, true) != PluginResult::OK) @@ -4706,9 +4717,9 @@ namespace QuickMedia { goto chat_page_end; } } - //all_messages.clear(); + tabs[MESSAGES_TAB_INDEX].body->clear_items(); Messages all_messages_new; -- cgit v1.2.3