Commit d4e49b8d authored by Camilo Higuita's avatar Camilo Higuita

playback work

parent 7e87b82b
......@@ -20,7 +20,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \
db/collectionDB.cpp \
settings/settings.cpp \
services/local/taginfo.cpp
services/local/taginfo.cpp \
services/local/player.cpp
RESOURCES += qml.qrc
......@@ -43,5 +44,6 @@ HEADERS += \
utils/bae.h \
settings/settings.h \
settings/fileloader.h \
services/local/taginfo.h
services/local/taginfo.h \
services/local/player.h
......@@ -5,6 +5,7 @@
#include "db/collectionDB.h"
#include "utils/bae.h"
#include "settings/settings.h"
#include "services/local/player.h"
int main(int argc, char *argv[])
{
......@@ -18,9 +19,11 @@ int main(int argc, char *argv[])
auto context = engine.rootContext();
CollectionDB con;
settings settings;
Player player;
context->setContextProperty("con", &con);
context->setContextProperty("set", &settings);
context->setContextProperty("player", &player);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
......
......@@ -3,11 +3,12 @@ import QtQuick.Controls 2.2
import QtLocation 5.9
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import QtMultimedia 5.8
import org.kde.kirigami 2.0 as Kirigami
import "utils/Icons.js" as MdiFont
import "utils/Player.js" as Player
import "utils"
import "view_models"
import "widgets"
......@@ -20,12 +21,13 @@ Kirigami.ApplicationWindow
height: 500
title: qsTr("Babe")
property int defaultColumnWidth: Kirigami.Units.gridUnit * 13
property int columnWidth: defaultColumnWidth
property int columnWidth: Kirigami.Units.gridUnit * 13
property int currentView : 0
property int iconSize
property var currentTrack
signal appendTrack(var track)
pageStack.defaultColumnWidth: columnWidth
......@@ -33,15 +35,18 @@ Kirigami.ApplicationWindow
Connections
{
target: con
onQmlSignal: console.log("lalaland")
}
MediaPlayer
{
id: player
volume: 1
target: player
onPos:
{
progressBar.value = pos
}
onFinished:
{
mainPlaylistTable.currentIndex = mainPlaylistTable.currentIndex+1 || 0
var track = mainPlaylistTable.model.get(mainPlaylistTable.currentIndex);
Player.playTrack(track)
}
}
header: BabeBar
......@@ -56,11 +61,6 @@ Kirigami.ApplicationWindow
onArtistsViewClicked: currentView = 2
onPlaylistsViewClicked: currentView = 3
onSettingsViewClicked: currentView = 4
onPlaylistClicked:
{
con.test()
}
}
onAppendTrack:
......@@ -68,14 +68,20 @@ Kirigami.ApplicationWindow
mainPlaylistTable.model.append(track)
}
Page
{
id: playlistPage
width: parent.width
height: parent.height
Component.onCompleted:
{
if(mainPlaylistTable.count>0)
root.width = columnWidth
else
root.width = columnWidth*3
}
ColumnLayout
{
......@@ -114,7 +120,9 @@ Kirigami.ApplicationWindow
Layout.fillWidth: true
anchors.top: coverPlay.bottom
height: 16
value: 0.5
from: 0
to: 1000
value: 0
}
Rectangle
......@@ -138,24 +146,31 @@ Kirigami.ApplicationWindow
{
id: previousBtn
Icon {text: MdiFont.Icon.skipPrevious}
onClicked: Player.previousTrack()
}
ToolButton
{
id: playBtn
Icon{text: MdiFont.Icon.play}
id: babeBtn
Icon{text: MdiFont.Icon.heartOutline}
}
ToolButton
{
id: pauseBtn
id: playBtn
Icon{text: MdiFont.Icon.pause}
onClicked:
{
Player.pauseTrack()
}
}
ToolButton
{
id: nextBtn
Icon{text: MdiFont.Icon.skipNext}
onClicked: Player.nextTrack()
}
}
}
......@@ -173,15 +188,11 @@ Kirigami.ApplicationWindow
id: mainPlaylistTable
width: parent.width
height: parent.height
clip: true
onRowClicked:
{
console.log(model.get(index).url)
player.source = model.get(index).url;
player.play();
console.log(player.playbackState)
Player.playTrack(model.get(index))
}
}
}
}
......@@ -216,7 +227,13 @@ Kirigami.ApplicationWindow
}
}
AlbumsView {}
AlbumsView
{
onRowClicked:
{
appendTrack(track)
}
}
ArtistsView {}
......
......@@ -21,5 +21,6 @@
<file>assets/test.jpg</file>
<file>db/script.sql</file>
<file>widgets/SettingsView.qml</file>
<file>utils/Player.js</file>
</qresource>
</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
onWidthChanged:
{
var amount = parseInt(grid.width/(albumSize+albumSpacing),10)
var leftSpace = parseInt(grid.width-(amount*albumSize), 10)
var size = parseInt(albumSize+(parseInt(leftSpace/amount, 10)), 10)
// var amount = parseInt(grid.width/(albumSize+albumSpacing),10)
// var leftSpace = parseInt(grid.width-(amount*albumSize), 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.cellHeight = size
// grid.cellWidth = size
// // grid.cellHeight = size
console.log(parseInt(size,10))
// console.log(parseInt(size,10))
}
delegate: BabeAlbum
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ListView
{
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
property int currentRow : -1
signal rowClicked(int index)
signal rowPressed(int index)
......@@ -10,6 +13,9 @@ ListView
width: 320
height: 480
highlight: highlight
highlightFollowsCurrentItem: false
focus: true
boundsBehavior: Flickable.StopAtBounds
......@@ -18,6 +24,34 @@ ListView
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
{
id: contextMenu
......@@ -87,6 +121,7 @@ ListView
onClicked:
{
list.rowClicked(index)
currentIndex = index
}
}
}
......
......@@ -13,8 +13,7 @@ BabeGrid
albumSize: 150
borderRadius: 20
property string drawerAlbum
property string drawerArtist
signal rowClicked(var track)
Drawer
{
......@@ -44,7 +43,6 @@ BabeGrid
id: albumTitle
width: parent.width - closeBtn.width
height: parent.height
text: drawerAlbum
elide: Text.ElideRight
font.pointSize: 12
font.bold: true
......@@ -80,7 +78,10 @@ BabeGrid
id: drawerList
width: parent.width
height: parent.height - titleBar.height
onRowClicked:
{
albumsView.rowClicked(model.get(index))
}
}
}
......@@ -88,19 +89,17 @@ BabeGrid
onAlbumCoverClicked:
{
drawerAlbum = album
drawerArtist = artist
albumTitle.text = album
drawer.open()
console.log("haha: ", album, artist)
var query = "select * from tracks where album = \""+albumsView.drawerAlbum+"\" and artist = \""+albumsView.drawerArtist+"\""
drawerList.clearTable()
var query = "select * from tracks where album = \""+album+"\" and artist = \""+artist+"\""
console.log(query)
var map = con.get(query)
for(var i in map)
{
drawerList.model.append(map[i])
console.log(map[i].title)
}
}
......
......@@ -87,6 +87,21 @@ BabeGrid
artistTitle.text = artist
drawer.open()
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
signal artistsViewClicked()
signal playlistsViewClicked()
signal settingsViewClicked()
signal playlistClicked()
id: babeBar
......@@ -35,20 +34,6 @@ ToolBar
RowLayout
{
anchors.fill: parent
ToolButton
{
id: playlistView
Icon
{
text: MdiFont.Icon.playCircle
color: currentIndex === -1? accentColor : textColor
iconSize: size
}
ToolTip { text: "Playlist" }
onClicked: playlistClicked()
}
Row
{
......
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