diff options
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | include/VideoPlayer.hpp | 9 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 4 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 36 |
4 files changed, 53 insertions, 12 deletions
@@ -1,16 +1,20 @@ # QuickMedia Native clients of websites with fast access to what you want to see. [Demo with manga](https://beta.lbry.tv/quickmedia_manga-2019-08-05_21.20.46/7). -Press `ctrl + t` when hovering over a manga chapter to start tracking manga after that chapter. This only works if AutoMedia is installed and +## Controls +Press `ESC` to go back to the previous menu.\ +Press `Ctrl + T` when hovering over a manga chapter to start tracking manga after that chapter. This only works if AutoMedia is installed and accessible in PATH environment variable. +## Video controls +Press `space` to pause/unpause video. `Double-click` video to fullscreen or leave fullscreen. # Dependencies ## Compile See project.conf \[dependencies]. ## Runtime ### Required -curl needs to be downloaded for network requests. +`curl` needs to be downloaded for network requests. ### Optional -youtube-dl needs to be installed to play videos from youtube.\ -notify-send needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system). +`youtube-dl` needs to be installed to play videos from youtube.\ +`notify-send` needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system). # TODO Fix x11 freeze that sometimes happens when playing video.\ If a search returns no results, then "No results found for ..." should be shown and navigation should go back to searching with suggestions.\ @@ -23,4 +27,6 @@ until all subtitles have been downloaded and loaded. Figure out why memory usage doesn't drop much when killing the video player. Is it a bug in proprietary nvidia drivers on gnu/linux?\ Add grid-view when thumbnails are visible.\ Add scrollbar.\ -Add option to scale image to window size. +Add option to scale image to window size.\ +If you search too fast the search suggestion wont show up and when you press enter it will clear and you wont progress. +The search should wait until there are search results before clearing the search field and selecting the search suggestion.
\ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index 0ae05b0..4f60883 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -26,10 +26,10 @@ namespace QuickMedia { class VideoPlayer { public: // Throws VideoInitializationException on error - VideoPlayer(sf::RenderWindow &window, unsigned int width, unsigned int height, const char *file, bool loop = false); + VideoPlayer(sf::RenderWindow *window, unsigned int width, unsigned int height, const char *file, bool loop = false); ~VideoPlayer(); - void handleEvent(sf::Event &event); + void handle_event(sf::Event &event); void setPosition(float x, float y); void resize(const sf::Vector2f &size); void draw(sf::RenderWindow &window); @@ -42,6 +42,7 @@ namespace QuickMedia { std::atomic_bool event_update; PlaybackEndedCallback onPlaybackEndedCallback; private: + void on_doubleclick(); void handle_mpv_events(); private: mpv_handle *mpv; @@ -55,5 +56,9 @@ namespace QuickMedia { sf::RectangleShape seekbar; sf::RectangleShape seekbar_background; sf::Clock cursor_last_active_timer; + sf::Clock time_since_last_left_click; + int left_click_counter; + sf::RenderWindow *window; + bool video_is_fullscreen; }; } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 856fc73..4fa5f35 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -323,7 +323,7 @@ namespace QuickMedia { std::unique_ptr<VideoPlayer> video_player = nullptr; try { printf("Play video: %s\n", content_url.c_str()); - video_player.reset(new VideoPlayer(window, window_size.x, window_size.y, content_url.c_str())); + video_player.reset(new VideoPlayer(&window, window_size.x, window_size.y, content_url.c_str())); } catch(VideoInitializationException &e) { show_notification("Video player", "Failed to create video player", Urgency::CRITICAL); video_player = nullptr; @@ -365,7 +365,7 @@ namespace QuickMedia { if(video_player) { if(event.type == sf::Event::Resized) video_player->resize(window_size); - video_player->handleEvent(event); + video_player->handle_event(event); } } diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 505f74b..62fc7d2 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -8,6 +8,8 @@ #include <cmath> const int UI_VISIBLE_TIMEOUT_MS = 2500; +const int DOUBLE_CLICK_TIME = 500; +const auto pause_key = sf::Keyboard::Space; namespace QuickMedia { static void* getProcAddressMpv(void *funcContext, const char *name) { @@ -51,7 +53,7 @@ namespace QuickMedia { sf::Context *context; }; - VideoPlayer::VideoPlayer(sf::RenderWindow &window, unsigned int width, unsigned int height, const char *file, bool loop) : + VideoPlayer::VideoPlayer(sf::RenderWindow *_window, unsigned int width, unsigned int height, const char *file, bool loop) : redraw(false), event_update(false), onPlaybackEndedCallback(nullptr), @@ -59,7 +61,10 @@ namespace QuickMedia { mpvGl(nullptr), context(nullptr), textureBuffer(nullptr), - desired_size(width, height) + desired_size(width, height), + left_click_counter(0), + window(_window), + video_is_fullscreen(false) { //ContextScope context_scope(context.get()); texture.setSmooth(true); @@ -133,12 +138,37 @@ namespace QuickMedia { //mpv_detach_destroy(mpv); mpv_terminate_destroy(mpv); } + + if(video_is_fullscreen) + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Default); } - void VideoPlayer::handleEvent(sf::Event &event) { + void VideoPlayer::handle_event(sf::Event &event) { if(event.type == sf::Event::MouseMoved) { cursor_last_active_timer.restart(); + } else if(event.type == sf::Event::KeyPressed) { + if(event.key.code == pause_key) { + mpv_command_string(mpv, "cycle pause"); + } + } else if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) { + if(time_since_last_left_click.restart().asMilliseconds() <= DOUBLE_CLICK_TIME) { + if(++left_click_counter == 2) { + on_doubleclick(); + left_click_counter = 0; + } + } else { + left_click_counter = 1; + } + } + } + + void VideoPlayer::on_doubleclick() { + if(video_is_fullscreen) { + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Default); + } else { + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Fullscreen); } + video_is_fullscreen = !video_is_fullscreen; } void VideoPlayer::setPosition(float x, float y) { |