diff --git a/VideoPlayer.qml b/VideoPlayer.qml index 676de2e..b3b7033 100644 --- a/VideoPlayer.qml +++ b/VideoPlayer.qml @@ -9,8 +9,8 @@ Rectangle { visible: Player.hasVideo color: Colors.surface1 - width: childrenRect.width - height: childrenRect.height + // width: childrenRect.width + height: 64 ColumnLayout { anchors.fill: parent diff --git a/ViewVideoList.qml b/ViewVideoList.qml index cd97433..8cca739 100644 --- a/ViewVideoList.qml +++ b/ViewVideoList.qml @@ -4,18 +4,23 @@ import QtQuick.Layouts 6.8 import QYRComponents 1.0 -Item { +ColumnLayout { anchors.fill: parent property bool loading: true property bool failed: false - VideoPlayer {} + VideoPlayer { + Layout.fillWidth: true + Layout.fillHeight: false + } GridView { - anchors.horizontalCenter: parent.horizontalCenter + Layout.fillWidth: true + Layout.fillHeight: true + // anchors.horizontalCenter: parent.horizontalCenter visible: !loading || !failed - anchors.fill: parent + // anchors.fill: parent model: ListModel { id: model } clip: true diff --git a/player.cpp b/player.cpp index a3724f5..60d4504 100644 --- a/player.cpp +++ b/player.cpp @@ -65,7 +65,12 @@ void Player::loadVideo(QString id) { this->unloadVideo(); } - const QNetworkReply* reply = this->manager.get(QNetworkRequest(QUrl("https://youvideo.nonamesoft.xyz/youvideo/video/" + id))); + QNetworkReply* reply = this->manager.get(QNetworkRequest(QUrl("https://youvideo.nonamesoft.xyz/youvideo/video/" + id))); + + QEventLoop loop(this); + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + if (reply->error() != QNetworkReply::NoError) { qDebug() << "Player::loadVideo(): Video " << id << " doesn't exist!\n"; @@ -73,18 +78,22 @@ void Player::loadVideo(QString id) return; } - qDebug() << "Player::fetchMetadata(): Yippie! Got video " << id << "\n"; + const QJsonDocument data = QJsonDocument::fromJson(reply->readAll()); - this->player.setSource(QUrl("https://youvideo.nonamesoft.xyz/youvideo/api/" + id)); + this->player.setSource(QUrl("https://youvideo.nonamesoft.xyz/youvideo/api/videofile/with_extension/" + id + data ["extension"].toString())); - // Signals will be sent by shit sent from player + emit this->hasVideoChanged(); + emit this->loadingChanged(); this->m_failed = false; emit this->failedChanged(); + qDebug() << "Player::loadVideo(): Loaded video https://youvideo.nonamesoft.xyz/youvideo/api/videofile/with_extension/" + id + data ["extension"].toString(); + delete reply; } void Player::unloadVideo() { + qDebug("Player::unloadVideo(): Video unloaded"); this->player.setSource(QUrl("")); this->player.stop(); this->m_failed = false; @@ -97,16 +106,18 @@ void Player::unloadVideo() { void Player::play() { - if (!this->hasVideo() || !this->loading()) + qDebug() << "Player::play(): Can't play video?" << this->hasVideo() << this->loading(); + if (!this->hasVideo() || this->loading()) { return; - } + } this->player.play(); } void Player::pause() { - if (!this->hasVideo() || !this->loading()) + qDebug() << "Player::pause(): Can't pause video?" << (!this->hasVideo() || this->loading()); + if (!this->hasVideo() || this->loading()) { return; } @@ -115,7 +126,8 @@ void Player::pause() void Player::stop() { - if (!this->hasVideo() || !this->loading()) + qDebug() << "Player::stop(): Can't stop video?" << (!this->hasVideo() || this->loading()); + if (!this->hasVideo() || this->loading()) { return; }