#pragma once #include #include #include #include #include #include #include #include #include #include class mpv_handle; class mpv_opengl_cb_context; namespace QuickMedia { class VideoInitializationException : public std::runtime_error { public: VideoInitializationException(const std::string &errMsg) : std::runtime_error(errMsg) {} }; using PlaybackEndedCallback = std::function; class VideoPlayer { public: // Throws VideoInitializationException on error VideoPlayer(unsigned int width, unsigned int height, sf::WindowHandle window_handle, const char *file, bool loop = false); ~VideoPlayer(); void setPosition(float x, float y); void resize(const sf::Vector2i &size); void draw(sf::RenderWindow &window); // @path can also be an url if youtube-dl is installed void load_file(const std::string &path); // This counter is incremented when mpv wants to redraw content std::atomic_int redrawCounter; PlaybackEndedCallback onPlaybackEndedCallback; private: mpv_handle *mpv; mpv_opengl_cb_context *mpvGl; std::unique_ptr context; sf::Sprite sprite; sf::Texture texture; sf::Uint8 *textureBuffer; sf::Vector2i video_size; sf::Vector2i desired_size; sf::RectangleShape seekbar; sf::RectangleShape seekbar_background; }; }