aboutsummaryrefslogtreecommitdiff
path: root/include/VideoPlayer.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-04 02:28:33 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-04 02:28:36 +0200
commit4b24638802385816fb5f90c95f175b30ae2398a8 (patch)
treeab6c7cbfd7d20c2065e160f6e8f20be02e4cc1b5 /include/VideoPlayer.hpp
parentd9fb89269fd30fa44d2b3728b9ae3c7b896a77d3 (diff)
Add youtube video playing, page navigation
Diffstat (limited to 'include/VideoPlayer.hpp')
-rw-r--r--include/VideoPlayer.hpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp
new file mode 100644
index 0000000..e98221e
--- /dev/null
+++ b/include/VideoPlayer.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <SFML/Graphics/RenderWindow.hpp>
+#include <SFML/Graphics/Texture.hpp>
+#include <SFML/Graphics/Sprite.hpp>
+#include <SFML/Window/Context.hpp>
+#include <thread>
+#include <mutex>
+#include <atomic>
+#include <stdexcept>
+
+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) {}
+ };
+
+ class VideoPlayer {
+ public:
+ // Throws VideoInitializationException on error
+ VideoPlayer(unsigned int width, unsigned int height, const char *file, bool loop = false);
+ ~VideoPlayer();
+
+ void setPosition(float x, float y);
+ bool resize(const sf::Vector2i &size);
+ void draw(sf::RenderWindow &window);
+
+ // This counter is incremented when mpv wants to redraw content
+ std::atomic_int redrawCounter;
+ private:
+ sf::Context context;
+ mpv_handle *mpv;
+ mpv_opengl_cb_context *mpvGl;
+ std::thread renderThread;
+ std::mutex renderMutex;
+ sf::Sprite sprite;
+ sf::Texture texture;
+ sf::Uint8 *textureBuffer;
+ bool alive;
+ sf::Vector2i video_size;
+ sf::Vector2i desired_size;
+ };
+}