Un inicio

This commit is contained in:
Ruben Garcalia
2026-08-07 04:35:28 +02:00
parent 2e80cb5c01
commit 4d1232821a
13 changed files with 519 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
#pragma once
#include <QObject>
#include <QString>
#include <QUrl>
#include <format>
#include <qcoreapplication.h>
#include <vector>
#include "logger.hpp"
class PlaylistController : public QObject {
Q_OBJECT
Q_PROPERTY(QUrl currentVideoSource READ currentVideoSource NOTIFY
currentVideoSourceChanged)
public:
explicit PlaylistController(QObject *parent = nullptr) : QObject(parent) {}
QUrl currentVideoSource() const { return m_currentVideoSource; }
Q_INVOKABLE void loadNextVideo() {
if (m_queue.size() == 0) {
Logger::info("Nothing left to play");
m_playing = false;
return;
}
QString video = m_queue.front();
Logger::info(std::format("Playing: {} in video {}", video.toStdString(), 1));
m_queue.erase(m_queue.begin());
QUrl newUrl = QUrl::fromLocalFile(video);
if (m_currentVideoSource != newUrl) {
m_currentVideoSource = newUrl;
emit currentVideoSourceChanged();
}
}
// Tengo que rehacer esto en algun momento para que tome la url y la procese en otro thread
// Y ya que me pongo con ello usar el doble buffer y permitir cargar listas enteras
Q_INVOKABLE void addToQueue(const QString path) {
int n_elements = m_queue.size();
m_queue.push_back(path);
Logger::info(std::format("Adding: {}", path.toStdString()));
if (n_elements == 0 && !m_playing) {
m_playing = true;
loadNextVideo();
}
}
signals:
void currentVideoSourceChanged();
private:
bool m_playing = false;
std::vector<QString> m_queue = std::vector<QString>();
QUrl m_currentVideoSource = QString("");
};