Commit d4e49b8d authored by Camilo Higuita's avatar Camilo Higuita

playback work

parent 7e87b82b
...@@ -20,7 +20,8 @@ DEFINES += QT_DEPRECATED_WARNINGS ...@@ -20,7 +20,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \ SOURCES += main.cpp \
db/collectionDB.cpp \ db/collectionDB.cpp \
settings/settings.cpp \ settings/settings.cpp \
services/local/taginfo.cpp services/local/taginfo.cpp \
services/local/player.cpp
RESOURCES += qml.qrc RESOURCES += qml.qrc
...@@ -43,5 +44,6 @@ HEADERS += \ ...@@ -43,5 +44,6 @@ HEADERS += \
utils/bae.h \ utils/bae.h \
settings/settings.h \ settings/settings.h \
settings/fileloader.h \ settings/fileloader.h \
services/local/taginfo.h services/local/taginfo.h \
services/local/player.h
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "db/collectionDB.h" #include "db/collectionDB.h"
#include "utils/bae.h" #include "utils/bae.h"
#include "settings/settings.h" #include "settings/settings.h"
#include "services/local/player.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -18,9 +19,11 @@ int main(int argc, char *argv[]) ...@@ -18,9 +19,11 @@ int main(int argc, char *argv[])
auto context = engine.rootContext(); auto context = engine.rootContext();
CollectionDB con; CollectionDB con;
settings settings; settings settings;
Player player;
context->setContextProperty("con", &con); context->setContextProperty("con", &con);
context->setContextProperty("set", &settings); context->setContextProperty("set", &settings);
context->setContextProperty("player", &player);
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
......
...@@ -3,11 +3,12 @@ import QtQuick.Controls 2.2 ...@@ -3,11 +3,12 @@ import QtQuick.Controls 2.2
import QtLocation 5.9 import QtLocation 5.9
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import QtMultimedia 5.8
import org.kde.kirigami 2.0 as Kirigami import org.kde.kirigami 2.0 as Kirigami
import "utils/Icons.js" as MdiFont import "utils/Icons.js" as MdiFont
import "utils/Player.js" as Player
import "utils" import "utils"
import "view_models" import "view_models"
import "widgets" import "widgets"
...@@ -20,12 +21,13 @@ Kirigami.ApplicationWindow ...@@ -20,12 +21,13 @@ Kirigami.ApplicationWindow
height: 500 height: 500
title: qsTr("Babe") title: qsTr("Babe")
property int columnWidth: Kirigami.Units.gridUnit * 13
property int defaultColumnWidth: Kirigami.Units.gridUnit * 13
property int columnWidth: defaultColumnWidth
property int currentView : 0 property int currentView : 0
property int iconSize property int iconSize
property var currentTrack
signal appendTrack(var track) signal appendTrack(var track)
pageStack.defaultColumnWidth: columnWidth pageStack.defaultColumnWidth: columnWidth
...@@ -33,15 +35,18 @@ Kirigami.ApplicationWindow ...@@ -33,15 +35,18 @@ Kirigami.ApplicationWindow
Connections Connections
{ {
target: con target: player
onQmlSignal: console.log("lalaland") onPos:
} {
progressBar.value = pos
MediaPlayer }
{
id: player
volume: 1
onFinished:
{
mainPlaylistTable.currentIndex = mainPlaylistTable.currentIndex+1 || 0
var track = mainPlaylistTable.model.get(mainPlaylistTable.currentIndex);
Player.playTrack(track)
}
} }
header: BabeBar header: BabeBar
...@@ -56,11 +61,6 @@ Kirigami.ApplicationWindow ...@@ -56,11 +61,6 @@ Kirigami.ApplicationWindow
onArtistsViewClicked: currentView = 2 onArtistsViewClicked: currentView = 2
onPlaylistsViewClicked: currentView = 3 onPlaylistsViewClicked: currentView = 3
onSettingsViewClicked: currentView = 4 onSettingsViewClicked: currentView = 4
onPlaylistClicked:
{
con.test()
}
} }
onAppendTrack: onAppendTrack:
...@@ -68,14 +68,20 @@ Kirigami.ApplicationWindow ...@@ -68,14 +68,20 @@ Kirigami.ApplicationWindow
mainPlaylistTable.model.append(track) mainPlaylistTable.model.append(track)
} }
Page Page
{ {
id: playlistPage id: playlistPage
width: parent.width width: parent.width
height: parent.height height: parent.height
Component.onCompleted:
{
if(mainPlaylistTable.count>0)
root.width = columnWidth
else
root.width = columnWidth*3
}
ColumnLayout ColumnLayout
{ {
...@@ -114,7 +120,9 @@ Kirigami.ApplicationWindow ...@@ -114,7 +120,9 @@ Kirigami.ApplicationWindow
Layout.fillWidth: true Layout.fillWidth: true
anchors.top: coverPlay.bottom anchors.top: coverPlay.bottom
height: 16 height: 16
value: 0.5 from: 0
to: 1000
value: 0
} }
Rectangle Rectangle
...@@ -138,24 +146,31 @@ Kirigami.ApplicationWindow ...@@ -138,24 +146,31 @@ Kirigami.ApplicationWindow
{ {
id: previousBtn id: previousBtn
Icon {text: MdiFont.Icon.skipPrevious} Icon {text: MdiFont.Icon.skipPrevious}
onClicked: Player.previousTrack()
} }
ToolButton ToolButton
{ {
id: playBtn id: babeBtn
Icon{text: MdiFont.Icon.play} Icon{text: MdiFont.Icon.heartOutline}
} }
ToolButton ToolButton
{ {
id: pauseBtn id: playBtn
Icon{text: MdiFont.Icon.pause} Icon{text: MdiFont.Icon.pause}
onClicked:
{
Player.pauseTrack()
}
} }
ToolButton ToolButton
{ {
id: nextBtn id: nextBtn
Icon{text: MdiFont.Icon.skipNext} Icon{text: MdiFont.Icon.skipNext}
onClicked: Player.nextTrack()
} }
} }
} }
...@@ -173,15 +188,11 @@ Kirigami.ApplicationWindow ...@@ -173,15 +188,11 @@ Kirigami.ApplicationWindow
id: mainPlaylistTable id: mainPlaylistTable
width: parent.width width: parent.width
height: parent.height height: parent.height
clip: true
onRowClicked: onRowClicked:
{ {
console.log(model.get(index).url) Player.playTrack(model.get(index))
player.source = model.get(index).url;
player.play();
console.log(player.playbackState)
} }
} }
} }
} }
...@@ -216,7 +227,13 @@ Kirigami.ApplicationWindow ...@@ -216,7 +227,13 @@ Kirigami.ApplicationWindow
} }
} }
AlbumsView {} AlbumsView
{
onRowClicked:
{
appendTrack(track)
}
}
ArtistsView {} ArtistsView {}
......
...@@ -21,5 +21,6 @@ ...@@ -21,5 +21,6 @@
<file>assets/test.jpg</file> <file>assets/test.jpg</file>
<file>db/script.sql</file> <file>db/script.sql</file>
<file>widgets/SettingsView.qml</file> <file>widgets/SettingsView.qml</file>
<file>utils/Player.js</file>
</qresource> </qresource>
</RCC> </RCC>
#include "player.h"
Player::Player(QObject *parent) : QObject(parent)
{
this->player = new QMediaPlayer(this);
this->player->setVolume(100);
this->updater = new QTimer(this);
connect(this->updater, &QTimer::timeout, this, &Player::update);
}
void Player::source(const QString &url)
{
this->sourceurl = url;
this->player->setMedia(QUrl::fromLocalFile(this->sourceurl));
qDebug()<<this->player->metaData("Title").toString();
}
void Player::play()
{
if(sourceurl.isEmpty()) return;
if(!updater->isActive())
this->updater->start(100);
this->player->play();
}
void Player::pause()
{
this->player->pause();
}
void Player::stop()
{
this->player->stop();
this->updater->stop();
}
void Player::seek(const int &pos)
{
this->player->setPosition(pos);
}
int Player::duration()
{
if(this->sourceurl.isEmpty()) return 0;
return static_cast<int>(this->player->duration());
}
void Player::update()
{
emit this->pos(static_cast<int>(static_cast<double>(this->player->position())/this->player->duration()*1000));
if(this->player->state() == QMediaPlayer::StoppedState)
emit this->finished();
}
#ifndef PLAYER_H
#define PLAYER_H
#include <QObject>
#include <QtMultimedia/QMediaPlayer>
#include <QTimer>
class Player : public QObject
{
Q_OBJECT
public:
explicit Player(QObject *parent = nullptr);
Q_INVOKABLE void source(const QString &url);
Q_INVOKABLE void play();
Q_INVOKABLE void pause();
Q_INVOKABLE void stop();
Q_INVOKABLE void seek(const int &pos);
Q_INVOKABLE int duration();
private:
QMediaPlayer *player;
QTimer *updater;
void update();
QString sourceurl;
signals:
void pos(int pos);
void finished();
public slots:
};
#endif // PLAYER_H
function playTrack(track)
{
currentTrack = track
player.source(currentTrack.url);
player.play()
}
function pauseTrack()
{
player.pause()
}
function nextTrack()
{
var next = mainPlaylistTable.currentIndex+1 >= mainPlaylistTable.count? 0 : mainPlaylistTable.currentIndex+1
mainPlaylistTable.currentIndex = next
playTrack(mainPlaylistTable.model.get(next))
}
function previousTrack()
{
var previous = mainPlaylistTable.currentIndex-1 >= 0 ? mainPlaylistTable.currentIndex-1 : mainPlaylistTable.count-1
mainPlaylistTable.currentIndex = previous
playTrack(mainPlaylistTable.model.get(previous))
}
...@@ -43,16 +43,16 @@ Pane ...@@ -43,16 +43,16 @@ Pane
onWidthChanged: onWidthChanged:
{ {
var amount = parseInt(grid.width/(albumSize+albumSpacing),10) // var amount = parseInt(grid.width/(albumSize+albumSpacing),10)
var leftSpace = parseInt(grid.width-(amount*albumSize), 10) // var leftSpace = parseInt(grid.width-(amount*albumSize), 10)
var size = parseInt(albumSize+(parseInt(leftSpace/amount, 10)), 10) // var size = parseInt(albumSize+(parseInt(leftSpace/amount, 10)), 10)
size = size > albumSize+albumSpacing ? size : albumSize+albumSpacing // size = size > albumSize+albumSpacing ? size : albumSize+albumSpacing
grid.cellWidth = size // grid.cellWidth = size
// grid.cellHeight = size // // grid.cellHeight = size
console.log(parseInt(size,10)) // console.log(parseInt(size,10))
} }
delegate: BabeAlbum delegate: BabeAlbum
......
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
ListView ListView
{ {
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
property int currentRow : -1 property int currentRow : -1
signal rowClicked(int index) signal rowClicked(int index)
signal rowPressed(int index) signal rowPressed(int index)
...@@ -10,6 +13,9 @@ ListView ...@@ -10,6 +13,9 @@ ListView
width: 320 width: 320
height: 480 height: 480
highlight: highlight
highlightFollowsCurrentItem: false
focus: true focus: true
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
...@@ -18,6 +24,34 @@ ListView ...@@ -18,6 +24,34 @@ ListView
snapMode: ListView.SnapToItem snapMode: ListView.SnapToItem
function clearTable()
{
listModel.clear()
}
Component
{
id: highlight
Rectangle
{
width: list.width
height: list.currentItem.height
color: myPalette.highlight
opacity: 0.2
y: list.currentItem.y
Behavior on y
{
SpringAnimation
{
spring: 3
damping: 0.2
}
}
}
}
Menu Menu
{ {
id: contextMenu id: contextMenu
...@@ -87,6 +121,7 @@ ListView ...@@ -87,6 +121,7 @@ ListView
onClicked: onClicked:
{ {
list.rowClicked(index) list.rowClicked(index)
currentIndex = index
} }
} }
} }
......
...@@ -13,8 +13,7 @@ BabeGrid ...@@ -13,8 +13,7 @@ BabeGrid
albumSize: 150 albumSize: 150
borderRadius: 20 borderRadius: 20
property string drawerAlbum signal rowClicked(var track)
property string drawerArtist
Drawer Drawer
{ {
...@@ -44,7 +43,6 @@ BabeGrid ...@@ -44,7 +43,6 @@ BabeGrid
id: albumTitle id: albumTitle
width: parent.width - closeBtn.width width: parent.width - closeBtn.width
height: parent.height height: parent.height
text: drawerAlbum
elide: Text.ElideRight elide: Text.ElideRight
font.pointSize: 12 font.pointSize: 12
font.bold: true font.bold: true
...@@ -80,7 +78,10 @@ BabeGrid ...@@ -80,7 +78,10 @@ BabeGrid
id: drawerList id: drawerList
width: parent.width width: parent.width
height: parent.height - titleBar.height height: parent.height - titleBar.height
onRowClicked:
{
albumsView.rowClicked(model.get(index))
}
} }
} }
...@@ -88,19 +89,17 @@ BabeGrid ...@@ -88,19 +89,17 @@ BabeGrid
onAlbumCoverClicked: onAlbumCoverClicked:
{ {
drawerAlbum = album albumTitle.text = album
drawerArtist = artist
drawer.open() drawer.open()
console.log("haha: ", album, artist) drawerList.clearTable()
var query = "select * from tracks where album = \""+albumsView.drawerAlbum+"\" and artist = \""+albumsView.drawerArtist+"\""
var query = "select * from tracks where album = \""+album+"\" and artist = \""+artist+"\""
console.log(query) console.log(query)
var map = con.get(query) var map = con.get(query)
for(var i in map) for(var i in map)
{
drawerList.model.append(map[i]) drawerList.model.append(map[i])
console.log(map[i].title)
}
} }
......
...@@ -87,6 +87,21 @@ BabeGrid ...@@ -87,6 +87,21 @@ BabeGrid
artistTitle.text = artist artistTitle.text = artist
drawer.open() drawer.open()
console.log("haha: ", album, artist) console.log("haha: ", album, artist)
var query = "select * from tracks where artist = \""+artist+"\""
var map = con.get(query)
for(var i in map)
drawerList.model.append(map[i])
}
Component.onCompleted:
{
var map = con.get("select * from artists")
for(var i in map)
{
gridModel.append(map[i])
}
} }
} }
...@@ -20,7 +20,6 @@ ToolBar ...@@ -20,7 +20,6 @@ ToolBar
signal artistsViewClicked() signal artistsViewClicked()
signal playlistsViewClicked() signal playlistsViewClicked()
signal settingsViewClicked() signal settingsViewClicked()
signal playlistClicked()
id: babeBar id: babeBar
...@@ -35,20 +34,6 @@ ToolBar ...@@ -35,20 +34,6 @@ ToolBar
RowLayout RowLayout
{ {
anchors.fill: parent anchors.fill: parent
ToolButton
{
id: playlistView