Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 1c895ed5 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MPV: The video is now correctly loading when loading a document!

parent 0959953b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
...@@ -77,7 +77,7 @@ MpvContainer::closeMpv() noexcept ...@@ -77,7 +77,7 @@ MpvContainer::closeMpv() noexcept
MpvContainer::~MpvContainer() noexcept { closeMpv(); } MpvContainer::~MpvContainer() noexcept { closeMpv(); }
void void
MpvContainer::handleMpvEvent(mpv_event *event) noexcept MpvContainer::handleMpvEvent(const mpv_event *const event) noexcept
{ {
// Declare here variables that can be used in the switch-case statements // Declare here variables that can be used in the switch-case statements
qint64 w, h; qint64 w, h;
...@@ -88,8 +88,8 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept ...@@ -88,8 +88,8 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept
mpv_event_property *prop; mpv_event_property *prop;
}; };
auto checkProp = [](mpv_event_property *prop_, const std::string &str, auto checkProp = [](const mpv_event_property *const prop_, const std::string_view str,
int format) noexcept -> bool { const int format) noexcept -> bool {
return (prop_->name == str) && (prop_->format == format); return (prop_->name == str) && (prop_->format == format);
}; };
...@@ -114,17 +114,17 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept ...@@ -114,17 +114,17 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept
case MPV_EVENT_PROPERTY_CHANGE: case MPV_EVENT_PROPERTY_CHANGE:
prop = reinterpret_cast<mpv_event_property *>(event->data); prop = reinterpret_cast<mpv_event_property *>(event->data);
if (checkProp(prop, "time-pos"s, MPV_FORMAT_DOUBLE) && mpvTimeCallback) { if (checkProp(prop, "time-pos", MPV_FORMAT_DOUBLE) && mpvTimeCallback) {
time = *reinterpret_cast<double *>(prop->data); time = *reinterpret_cast<double *>(prop->data);
mpvTimeCallback(time); mpvTimeCallback(time);
} }
else if (checkProp(prop, "duration"s, MPV_FORMAT_DOUBLE) && mpvDurationCallback) { else if (checkProp(prop, "duration", MPV_FORMAT_DOUBLE) && mpvDurationCallback) {
time = *reinterpret_cast<double *>(prop->data); time = *reinterpret_cast<double *>(prop->data);
mpvDurationCallback(time); mpvDurationCallback(time);
} }
else if (checkProp(prop, "pause"s, MPV_FORMAT_FLAG)) { else if (checkProp(prop, "pause", MPV_FORMAT_FLAG)) {
isPlaybackPaused = *reinterpret_cast<bool *>(prop->data); isPlaybackPaused = *reinterpret_cast<bool *>(prop->data);
emit mpvPlaybackToggled(!isPlaybackPaused); emit mpvPlaybackToggled(!isPlaybackPaused);
qDebug() << "MPV -> set to" << (isPlaybackPaused ? "pause" : "play"); qDebug() << "MPV -> set to" << (isPlaybackPaused ? "pause" : "play");
...@@ -220,7 +220,7 @@ void ...@@ -220,7 +220,7 @@ void
MpvContainer::onMpvEvent() noexcept MpvContainer::onMpvEvent() noexcept
{ {
while (mpv) { while (mpv) {
mpv_event *event = mpv_wait_event(mpv, 0); const mpv_event *const event = mpv_wait_event(mpv, 0);
if (event == nullptr || event->event_id == MPV_EVENT_NONE) if (event == nullptr || event->event_id == MPV_EVENT_NONE)
break; break;
handleMpvEvent(event); handleMpvEvent(event);
...@@ -234,7 +234,8 @@ MpvContainer::onMpvEvent() noexcept ...@@ -234,7 +234,8 @@ MpvContainer::onMpvEvent() noexcept
void void
MpvContainer::loadFile(const QString &filename) noexcept MpvContainer::loadFile(const QString &filename) noexcept
{ {
if (filename.isEmpty()) qDebug() << "Loading file" << filename;
if (filename.size() == 0)
return; return;
const QByteArray cFileName = filename.toUtf8(); const QByteArray cFileName = filename.toUtf8();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include <QThread>
extern "C" { extern "C" {
struct mpv_handle; struct mpv_handle;
...@@ -27,12 +28,12 @@ class MpvContainer final : public QWidget { ...@@ -27,12 +28,12 @@ class MpvContainer final : public QWidget {
ReloadAss, ReloadAss,
UnloadAss, UnloadAss,
SeekTime, SeekTime,
TogglePlayback, TogglePlayback
}; };
private: private:
bool isPlaybackPaused{ true }; bool isPlaybackPaused{ true };
mpv_handle *mpv{ nullptr }; mpv_handle *volatile mpv{ nullptr };
qint64 sid{ -1 }; qint64 sid{ -1 };
std::function<void(double)> mpvTimeCallback{ nullptr }; std::function<void(double)> mpvTimeCallback{ nullptr };
std::function<void(double)> mpvDurationCallback{ nullptr }; std::function<void(double)> mpvDurationCallback{ nullptr };
...@@ -53,7 +54,7 @@ public: ...@@ -53,7 +54,7 @@ public:
void registerMpvDurationCallback(std::function<void(double)>) noexcept; void registerMpvDurationCallback(std::function<void(double)>) noexcept;
private: private:
void handleMpvEvent(mpv_event *) noexcept; void handleMpvEvent(const mpv_event *const) noexcept;
void closeMpv() noexcept; void closeMpv() noexcept;
void printMpvError(int) const noexcept; void printMpvError(int) const noexcept;
void asyncCommand(const AsyncCmdType, std::initializer_list<const char *>) noexcept; void asyncCommand(const AsyncCmdType, std::initializer_list<const char *>) noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter