added progress bar to show position in track
still todo: styling, positioning, output of current time and length
This commit is contained in:
parent
6eabd3cb75
commit
b013b69e8d
4 changed files with 63 additions and 6 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
import QtQuick.Controls.Styles 1.4
|
||||||
import QtGraphicalEffects 1.0
|
import QtGraphicalEffects 1.0
|
||||||
|
|
||||||
Item{
|
Item{
|
||||||
|
|
@ -38,6 +40,37 @@ Item{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgressBar{
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.margins: container.margins
|
||||||
|
/*anchors.bottom: buttons.top
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.leftMargin: 40
|
||||||
|
anchors.rightMargin: 40
|
||||||
|
anchors.topMargin: 10
|
||||||
|
anchors.bottomMargin: 10
|
||||||
|
*/
|
||||||
|
z:99
|
||||||
|
|
||||||
|
value: musicModel.pProgress
|
||||||
|
style:ProgressBarStyle {
|
||||||
|
background: Rectangle {
|
||||||
|
radius: 2
|
||||||
|
color: "magenta"
|
||||||
|
border.color: "gray"
|
||||||
|
border.width: 1
|
||||||
|
implicitWidth: 200
|
||||||
|
implicitHeight: 24
|
||||||
|
}
|
||||||
|
progress: Rectangle {
|
||||||
|
color: "lightsteelblue"
|
||||||
|
border.color: "steelblue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: controlPannel
|
id: controlPannel
|
||||||
|
|
||||||
|
|
@ -47,8 +80,9 @@ Item{
|
||||||
color: "#99ffffff"
|
color: "#99ffffff"
|
||||||
height: 120
|
height: 120
|
||||||
|
|
||||||
// @todo: use rowLayout instead?
|
|
||||||
Row{
|
Row{
|
||||||
|
id: buttons
|
||||||
spacing: 20
|
spacing: 20
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
|
@ -73,10 +107,6 @@ Item{
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.playPause();
|
musicModel.playPause();
|
||||||
/* if(imageSource == "qrc:/icon_play")
|
|
||||||
imageSource = "qrc:/icon_pause"
|
|
||||||
else
|
|
||||||
imageSource = "qrc:/icon_play"*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoundButton{
|
RoundButton{
|
||||||
|
|
@ -90,7 +120,6 @@ Item{
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.stopMusic();
|
musicModel.stopMusic();
|
||||||
//playPause.imageSource = "qrc:/icon_play"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoundButton{
|
RoundButton{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ MusicController::MusicController(QObject *parent) : QObject(parent)
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(mPlayer, SIGNAL(nextItemSet(VlcMedia*)), mModel, SLOT(onNextMediaSet(VlcMedia*)));
|
connect(mPlayer, SIGNAL(nextItemSet(VlcMedia*)), mModel, SLOT(onNextMediaSet(VlcMedia*)));
|
||||||
|
connect(mPlayer->mediaPlayer(), &VlcMediaPlayer::lengthChanged, mModel, &MusicModel::onLengthChanged);
|
||||||
|
connect(mPlayer->mediaPlayer(), &VlcMediaPlayer::timeChanged, mModel, &MusicModel::onTimeChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicController::~MusicController()
|
MusicController::~MusicController()
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ void MusicModel::stopMusic()
|
||||||
mIsPlaying = false;
|
mIsPlaying = false;
|
||||||
mHasNext = false;
|
mHasNext = false;
|
||||||
mHasPrevious = false;
|
mHasPrevious = false;
|
||||||
|
mCurrentMediaItemProgress = 0.0;
|
||||||
|
emit progressChanged();
|
||||||
emit hasNextChanged();
|
emit hasNextChanged();
|
||||||
emit hasPreviousChanged();
|
emit hasPreviousChanged();
|
||||||
emit isPlayingChanged();
|
emit isPlayingChanged();
|
||||||
|
|
@ -114,6 +116,11 @@ bool MusicModel::hasPrevious()
|
||||||
return mHasPrevious;
|
return mHasPrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double MusicModel::getProgress()
|
||||||
|
{
|
||||||
|
return mCurrentMediaItemProgress;
|
||||||
|
}
|
||||||
|
|
||||||
void MusicModel::onNextMediaSet(VlcMedia *media)
|
void MusicModel::onNextMediaSet(VlcMedia *media)
|
||||||
{
|
{
|
||||||
mHasNext = true;
|
mHasNext = true;
|
||||||
|
|
@ -127,3 +134,14 @@ void MusicModel::onNextMediaSet(VlcMedia *media)
|
||||||
emit hasPreviousChanged();
|
emit hasPreviousChanged();
|
||||||
emit hasNextChanged();
|
emit hasNextChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MusicModel::onTimeChanged(int time)
|
||||||
|
{
|
||||||
|
mCurrentMediaItemProgress = (double) time / mCurrentMediaItemLength;
|
||||||
|
emit progressChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::onLengthChanged(int length)
|
||||||
|
{
|
||||||
|
mCurrentMediaItemLength= length;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class MusicModel : public QObject
|
||||||
Q_PROPERTY(bool pHasNext READ hasNext NOTIFY hasNextChanged)
|
Q_PROPERTY(bool pHasNext READ hasNext NOTIFY hasNextChanged)
|
||||||
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
||||||
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
||||||
|
Q_PROPERTY(double pProgress READ getProgress NOTIFY progressChanged)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void navigateTo(NavigationItemModel *item);
|
void navigateTo(NavigationItemModel *item);
|
||||||
|
|
@ -26,6 +27,7 @@ signals:
|
||||||
void hasPreviousChanged();
|
void hasPreviousChanged();
|
||||||
void hasNextChanged();
|
void hasNextChanged();
|
||||||
void isPlayingChanged();
|
void isPlayingChanged();
|
||||||
|
void progressChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
||||||
|
|
@ -47,13 +49,19 @@ public:
|
||||||
bool hasNext();
|
bool hasNext();
|
||||||
bool hasPrevious();
|
bool hasPrevious();
|
||||||
|
|
||||||
|
double getProgress();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onNextMediaSet(VlcMedia* media);
|
void onNextMediaSet(VlcMedia* media);
|
||||||
|
void onTimeChanged(int time);
|
||||||
|
void onLengthChanged(int length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mIsPlaying = false;
|
bool mIsPlaying = false;
|
||||||
bool mHasNext = false;
|
bool mHasNext = false;
|
||||||
bool mHasPrevious = false;
|
bool mHasPrevious = false;
|
||||||
|
int mCurrentMediaItemLength = 0;
|
||||||
|
double mCurrentMediaItemProgress = 0;
|
||||||
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
||||||
VlcMediaList* mMedia = Q_NULLPTR;
|
VlcMediaList* mMedia = Q_NULLPTR;
|
||||||
VlcInstance* mVlc;
|
VlcInstance* mVlc;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue