Commit af89e3a5 authored by Camilo higuita's avatar Camilo higuita

more work to update vvave for better and faster performance

parent 90042196
......@@ -66,17 +66,17 @@ Babe::Babe(QObject *parent) : QObject(parent)
/*The local streaming connection still unfinished*/
connect(&link, &Linking::parseAsk, this, &Babe::linkDecoder);
connect(&link, &Linking::bytesFrame, [this](QByteArray array)
{
this->player.appendBuffe(array);
// connect(&link, &Linking::bytesFrame, [this](QByteArray array)
// {
// this->player.appendBuffe(array);
});
connect(&link, &Linking::arrayReady, [this](QByteArray array)
{
qDebug()<<"trying to play the array";
Q_UNUSED(array);
this->player.playBuffer();
});
// });
// connect(&link, &Linking::arrayReady, [this](QByteArray array)
// {
// qDebug()<<"trying to play the array";
// Q_UNUSED(array);
// this->player.playBuffer();
// });
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
this->nof = new Notify(this);
......
......@@ -6,7 +6,6 @@
#include "utils/bae.h"
#include "db/collectionDB.h"
#include "services/local/linking.h"
#include "services/local/player.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
class Notify;
......@@ -31,7 +30,6 @@ public:
BabeSettings *settings;
Linking link;
Player player;
// Q_INVOKABLE void runPy();
......
......@@ -3,6 +3,7 @@
#include <QObject>
#include <QThread>
#include <QVariant>
class CollectionDB;
class ConThread : public QObject
......
......@@ -30,6 +30,7 @@
#include "services/web/youtube.h"
#include "services/web/Spotify/spotify.h"
#include "services/local/linking.h"
#include "services/local/player.h"
#include "models/tracks/tracksmodel.h"
#include "models/baselist.h"
......@@ -95,7 +96,6 @@ int main(int argc, char *argv[])
});
auto context = engine.rootContext();
context->setContextProperty("player", &bae.player);
context->setContextProperty("bae", &bae);
context->setContextProperty("youtube", &youtube);
context->setContextProperty("spotify", &spotify);
......@@ -105,6 +105,9 @@ int main(int argc, char *argv[])
qmlRegisterType<BaseModel>("BaseModel", 1, 0, "BaseModel");
qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
qmlRegisterType<Player>("Player", 1, 0, "Player");
qmlRegisterUncreatableMetaObject(
LINK::staticMetaObject, // static meta object
"Link.Codes", // import statement (can be any string)
......
......@@ -29,6 +29,7 @@ import "utils/Player.js" as Player
import org.kde.kirigami 2.2 as Kirigami
import org.kde.mauikit 1.0 as Maui
import FMList 1.0
import Player 1.0
Maui.ApplicationWindow
{
......@@ -63,9 +64,9 @@ Maui.ApplicationWindow
property int prevTrackIndex: 0
property string currentArtwork: !mainlistEmpty ? mainPlaylist.list.model.get(0).artwork : ""
property bool currentBabe: currentTrack.babe == "0" ? false : true
property string durationTimeLabel: "00:00"
property string progressTimeLabel: "00:00"
property bool isPlaying: false
property string durationTimeLabel: player.duration
property string progressTimeLabel: player.transformTime(player.position/1000)
property bool isPlaying: player.playing
property bool autoplay: bae.loadSetting("AUTOPLAY", "BABE",
false) === "true" ? true : false
property int onQueue: 0
......@@ -162,6 +163,21 @@ Maui.ApplicationWindow
}
/*COMPONENTS*/
Player
{
id: player
volume: 100
onFinishedChanged: if (!mainlistEmpty)
{
if (currentTrack.url)
bae.playedTrack(currentTrack.url)
Player.nextTrack()
}
}
BabeNotify
{
id: babeNotify
......@@ -369,7 +385,7 @@ Maui.ApplicationWindow
}
Maui.MenuItem
{
{
text: qsTr("Refresh...")
onTriggered: H.refreshCollection();
}
......@@ -919,32 +935,15 @@ Maui.ApplicationWindow
/*CONNECTIONS*/
Connections
{
target: player
onPos: progressBar.value = pos
onTiming: progressTimeLabel = time
onDurationChanged: durationTimeLabel = time
onFinished: if (!mainlistEmpty)
{
if (currentTrack.url)
bae.playedTrack(currentTrack.url)
Player.nextTrack()
}
onIsPlaying: isPlaying = playing
}
Connections
{
target: bae
// onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
// onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
// onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
// onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
onTrackLyricsReady:
{
......
......@@ -120,6 +120,22 @@ QVariantMap TracksModel::get(const int &index) const
return res;
}
void TracksModel::append(const QVariantMap &item)
{
if(item.isEmpty())
return;
emit this->preItemAppended();
FMH::MODEL model;
for(auto key : item.keys())
model.insert(FMH::MODEL_NAME_KEY[key], item[key].toString());
this->list << model;
emit this->postItemAppended();
}
bool TracksModel::color(const int &index, const QString &color)
{
if(index >= this->list.size() || index < 0)
......
......@@ -40,6 +40,7 @@ signals:
public slots:
QVariantMap get(const int &index) const override;
void append(const QVariantMap &item);
bool color(const int &index, const QString &color);
};
......
......@@ -7,36 +7,25 @@ Player::Player(QObject *parent) : QObject(parent)
this->player = new QMediaPlayer(this);
this->buffer = new QBuffer(this->player);
connect(player, &QMediaPlayer::durationChanged, this, [&](qint64 dur)
connect(this->player, &QMediaPlayer::durationChanged, this, [&](qint64 dur)
{
emit this->durationChanged(BAE::transformTime(dur/1000));
emit this->durationChanged(/*BAE::transformTime(dur/1000)*/);
});
this->player->setVolume(100);
this->player->setVolume(this->volume);
this->updater = new QTimer(this);
connect(this->updater, &QTimer::timeout, this, &Player::update);
}
void Player::source(const QString &url)
{
this->sourceurl = url;
auto media = QMediaContent(QUrl::fromLocalFile(this->sourceurl));
qDebug()<<this->player->mediaStatus();
this->player->setMedia(media);
qDebug()<<this->player->mediaStatus();
}
bool Player::play()
{
if(sourceurl.isEmpty()) return false;
if(this->url.isEmpty()) return false;
if(!updater->isActive())
this->updater->start(150);
this->player->play();
this->player->play();
return true;
}
......@@ -52,30 +41,34 @@ void Player::stop()
if(this->player->isAvailable())
{
this->player->stop();
this->sourceurl = QString();
this->url = QString();
this->player->setMedia(QMediaContent());
}
emit this->isPlaying(false);
this->playing = false;
emit this->playingChanged();
this->updater->stop();
}
void Player::seek(const int &pos)
{
this->player->setPosition(pos);
this->emitState();
}
int Player::duration()
void Player::emitState()
{
if(this->sourceurl.isEmpty()) return 0;
return static_cast<int>(this->player->duration());
}
switch(this->player->state())
{
case QMediaPlayer::PlayingState:
this->state = Player::STATE::PLAYING;
break;
case QMediaPlayer::PausedState:
this->state = Player::STATE::PAUSED;
break;
case QMediaPlayer::StoppedState:
this->state = Player::STATE::STOPED;
break;
}
bool Player::isPaused()
{
return !(this->player->state() == QMediaPlayer::PlayingState);
emit this->stateChanged();
}
QString Player::transformTime(const int &pos)
......@@ -96,31 +89,118 @@ void Player::appendBuffe(QByteArray &array)
void Player::playRemote(const QString &url)
{
qDebug()<<"Trying to play remote"<<url;
this->sourceurl = url;
this->url = url;
this->player->setMedia(QUrl::fromUserInput(url));
this->play();
}
void Player::setUrl(const QString &value)
{
if(value == this->url)
return;
this->url = value;
emit this->urlChanged();
auto media = QMediaContent(QUrl::fromLocalFile(this->url));
this->player->setMedia(media);
this->emitState();
}
QString Player::getUrl() const
{
return this->url;
}
void Player::setVolume(const int &value)
{
if(value == this->volume)
return;
this->volume = value;
this->player->setVolume(volume);
emit this->volumeChanged();
}
int Player::getVolume() const
{
return this->volume;
}
int Player::getDuration() const
{
return static_cast<int>(this->player->duration());
}
void Player::setPosition(const int &value)
{
if(value == this->position)
return;
this->position = value;
this->positionChanged();
this->player->setPosition(position);
this->emitState();
}
int Player::getPosition() const
{
return static_cast<int>(this->player->position());
}
Player::STATE Player::getState() const
{
return this->state;
}
void Player::setPlaying(const bool &value)
{
if(value == this->playing)
return;
this->playing = value;
if(this->playing)
this->play();
else this->pause();
this->emitState();
}
bool Player::getPlaying() const
{
return this->playing;
}
bool Player::getFinished()
{
return this->finished;
}
void Player::playBuffer()
{
buffer->setData(array);
buffer->open(QIODevice::ReadOnly);
if(!buffer->isReadable()) qDebug()<<"Cannot read buffer";
player->setMedia(QMediaContent(),buffer);
this->sourceurl = "buffer";
this->url = "buffer";
this->play();
this->emitState();
}
void Player::update()
{
if(this->player->isAvailable())
{
emit this->pos(static_cast<int>(static_cast<double>(this->player->position())/this->player->duration()*1000));
emit this->timing(BAE::transformTime(player->position()/1000));
this->position = static_cast<int>(static_cast<double>(this->player->position())/this->player->duration()*1000);
emit this->positionChanged();
}
emit this->isPlaying(this->player->state() == QMediaPlayer::PlayingState ? true : false);
if(this->player->state() == QMediaPlayer::StoppedState && this->updater->isActive())
emit this->finished();
{
this->finished = true;
emit this->finishedChanged();
}
this->emitState();
}
#ifndef PLAYER_H
#ifndef PLAYER_H
#define PLAYER_H
#include <QObject>
......@@ -8,40 +8,81 @@
class Player : public QObject
{
Q_OBJECT
public:
explicit Player(QObject *parent = nullptr);
Q_INVOKABLE void source(const QString &url);
Q_INVOKABLE bool play();
Q_INVOKABLE void pause();
Q_INVOKABLE void stop();
Q_INVOKABLE void seek(const int &pos);
Q_INVOKABLE int duration();
Q_INVOKABLE bool isPaused();
Q_INVOKABLE QString transformTime(const int &pos);
Q_INVOKABLE void playBuffer();
Q_INVOKABLE void appendBuffe(QByteArray &array);
Q_INVOKABLE void playRemote(const QString &url);
private:
QMediaPlayer *player;
QTimer *updater;
int amountBuffers =0;
void update();
QBuffer *buffer;
QByteArray array;
QString sourceurl;
signals:
void pos(int pos);
void finished();
void timing(QString time);
void durationChanged(QString time);
void isPlaying(bool playing);
public slots:
Q_OBJECT
Q_PROPERTY(QString url READ getUrl WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(int volume READ getVolume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(int position READ getPosition WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(Player::STATE state READ getState NOTIFY stateChanged)
Q_PROPERTY(int duration READ getDuration NOTIFY durationChanged)
Q_PROPERTY(bool playing READ getPlaying WRITE setPlaying NOTIFY playingChanged)
Q_PROPERTY(bool finished READ getFinished NOTIFY finishedChanged)
public:
enum STATE : uint_fast8_t
{
PLAYING,
PAUSED,
STOPED,
ERROR
};Q_ENUM(STATE)
explicit Player(QObject *parent = nullptr);
void playBuffer();
Q_INVOKABLE void appendBuffe(QByteArray &array);
void setUrl(const QString &value);
QString getUrl() const;
void setVolume(const int &value);
int getVolume() const;
int getDuration() const;
void setPosition(const int &value);
int getPosition() const;
Player::STATE getState() const;
void setPlaying(const bool &value);
bool getPlaying() const;
bool getFinished();
private:
QMediaPlayer *player;
QTimer *updater;
int amountBuffers =0;
void update();
QBuffer *buffer;
QByteArray array;
QString url;
int volume = 100;
int position = 0;
Player::STATE state = STATE::STOPED;
bool playing = false;
bool finished = false;
bool play();
void pause();
void emitState();
signals:
void durationChanged();
void urlChanged();
void volumeChanged();
void positionChanged();
void stateChanged();
void playingChanged();
void finishedChanged();
public slots:
QString transformTime(const int &pos);
void playRemote(const QString &url);
void stop();
};
#endif // PLAYER_H
......@@ -11,8 +11,8 @@ function playTrack(index)
if(bae.fileExists(currentTrack.url))
{
player.source(currentTrack.url);
player.play()
player.url = currentTrack.url;
player.playing = true
var artwork = currentTrack.artwork
currentArtwork = artwork && artwork.length > 0 && artwork !== "NONE"? artwork : bae.loadCover(currentTrack.url)
......@@ -71,13 +71,13 @@ function stop()
function pauseTrack()
{
player.pause()
player.playing = false
}
function resumeTrack()
{
if(!player.play() && !mainlistEmpty)
playAt(0)
// if(!player.play() && !mainlistEmpty)
// playAt(0)
}
function nextTrack()
......@@ -149,7 +149,7 @@ function appendTrack(track)
{
if(track)
{
mainPlaylist.list.model.append(track)
mainPlaylist.list.append(track)
animFooter.running = true
if(sync === true)
{
......
......@@ -64,7 +64,9 @@ SOURCES += main.cpp \
services/local/linking.cpp \
settings/fileloader.cpp \
services/web/Spotify/spotify.cpp \
models/tracks/tracksmodel.cpp
models/tracks/tracksmodel.cpp \
models/basemodel.cpp \
models/baselist.cpp
RESOURCES += qml.qrc \
......@@ -100,7 +102,9 @@ HEADERS += \
services/local/youtubedl.h \
services/local/linking.h \
services/web/Spotify/spotify.h \
models/tracks/tracksmodel.h
models/tracks/tracksmodel.h \
models/basemodel.h \
models/baselist.h
include(install.pri)
......
......@@ -379,10 +379,13 @@ Maui.Page
padding: 0
from: 0
to: 1000
value: 0
value: player.position
spacing: 0
focus: true
onMoved: player.seek(player.duration() / 1000 * value)
onMoved:
{
player.position = player.duration / 1000 * value
}
background: Rectangle
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment