Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2022 Chupligin Sergey <neochapay@gmail.com> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "glaciermusicplayer.h" | ||
|
||
GlacierMusicPlayer::GlacierMusicPlayer(QObject *parent) | ||
: QObject(parent) | ||
, m_player(new QMediaPlayer) | ||
, m_settings(new QSettings) | ||
, m_coverAdapter(new Cover) | ||
{ | ||
connect(m_player, &QMediaPlayer::volumeChanged, this, &GlacierMusicPlayer::storeVolume); | ||
connect(m_player, &QMediaPlayer::positionChanged, this, &GlacierMusicPlayer::storePosition); | ||
connect(m_player, &QMediaPlayer::stateChanged, this, &GlacierMusicPlayer::storeState); | ||
|
||
m_player->setVolume(m_settings->value("volume").toInt()); | ||
|
||
connect(m_coverAdapter, &Cover::coverLoaing, this, &GlacierMusicPlayer::setDefaultCover); | ||
} | ||
|
||
QString GlacierMusicPlayer::cover() | ||
{ | ||
QString cover = "/usr/share/glacier-music/images/cover.png"; | ||
return cover; | ||
} | ||
|
||
float GlacierMusicPlayer::progress() | ||
{ | ||
if(m_player->duration() > 0) { | ||
return m_player->position()/m_player->duration(); | ||
} | ||
return 1; | ||
} | ||
|
||
void GlacierMusicPlayer::setProgress(float progress) | ||
{ | ||
qDebug() << Q_FUNC_INFO << "NOT IMPLEMENTED"; | ||
} | ||
|
||
void GlacierMusicPlayer::storeVolume(int volume) | ||
{ | ||
m_settings->setValue("volume", volume); | ||
m_settings->sync(); | ||
} | ||
|
||
void GlacierMusicPlayer::storePosition(qint64 position) | ||
{ | ||
if(m_player->state() == QMediaPlayer::PlayingState) { | ||
m_settings->setValue("seek", position); | ||
m_settings->sync(); | ||
} | ||
emit positionChanged(position); | ||
emit progressChanged(); | ||
} | ||
|
||
void GlacierMusicPlayer::storeState(QMediaPlayer::State newState) | ||
{ | ||
m_settings->setValue("playbackState", newState); | ||
} | ||
|
||
void GlacierMusicPlayer::setDefaultCover() | ||
{ | ||
QString cover = "/usr/share/glacier-music/images/cover.png"; | ||
if(cover != m_coverPath) { | ||
m_coverPath = cover; | ||
emit coverChanged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2022 Chupligin Sergey <neochapay@gmail.com> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef GLACIERMUSICPLAYER_H | ||
#define GLACIERMUSICPLAYER_H | ||
|
||
#include <QObject> | ||
#include <QMediaPlayer> | ||
#include <QSettings> | ||
|
||
#include "cover.h" | ||
|
||
class GlacierMusicPlayer : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(bool firstRun READ firstRun) | ||
Q_PROPERTY(QString cover READ cover NOTIFY coverChanged) | ||
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged) | ||
|
||
public: | ||
explicit GlacierMusicPlayer(QObject *parent = nullptr); | ||
bool firstRun() {return false;} | ||
|
||
QString cover(); | ||
|
||
float progress(); | ||
void setProgress(float progress); | ||
|
||
signals: | ||
void noMusicFiles(); | ||
void noSourcePlugins(); | ||
void coverChanged(); | ||
|
||
void positionChanged(qint64 position); | ||
void progressChanged(); | ||
|
||
private slots: | ||
void storeVolume(int volume); | ||
void storePosition(qint64 position); | ||
void storeState(QMediaPlayer::State newState); | ||
|
||
void setDefaultCover(); | ||
|
||
private: | ||
QMediaPlayer *m_player; | ||
QSettings* m_settings; | ||
Cover* m_coverAdapter; | ||
|
||
QString m_coverPath; | ||
}; | ||
|
||
#endif // GLACIERMUSICPLAYER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(local) |
Empty file.