-
Notifications
You must be signed in to change notification settings - Fork 2
/
musicmanager.h
63 lines (50 loc) · 1.71 KB
/
musicmanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef MUSICMANAGER_H
# define MUSICMANAGER_H
# include "globals.h"
# include <string>
# include <QTimer>
# include <QJsonObject>
# include <QMediaPlayer>
class MusicManager : public QObject
{
static MusicManager* _global_ptr;
Q_OBJECT
Q_PROPERTY(int defaultVolume READ getDefaultVolume WRITE setDefaultVolume NOTIFY defaultVolumeChanged)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
typedef QMediaPlayer::State PlaybackState;
#else
typedef QMediaPlayer::PlaybackState PlaybackState;
#endif
public:
explicit MusicManager(QObject* parent = nullptr);
~MusicManager();
static MusicManager* get(void) { return (_global_ptr); }
Q_INVOKABLE void play(const QString& category);
Q_INVOKABLE void play(const QString& category, const QString& name);
Q_INVOKABLE void pause(bool paused);
Q_INVOKABLE void playNext(void);
Q_INVOKABLE void setVolume(int volume);
Q_INVOKABLE void setVolumeToDefault(void);
void setDefaultVolume(int);
int getDefaultVolume() const;
signals:
void defaultVolumeChanged();
private slots:
void fadeOut();
void fadeVolume();
void onStateChanged(PlaybackState);
private:
void loadDataTree();
void startTrack(const QString& filename);
QStringList potentialSuccessors() const;
QJsonObject data;
QJsonObject dataTree;
QString currentCategory;
QTimer fadingTimer;
bool fadingOut;
int volumeGoal;
int volumeRef;
QMediaPlayer* audioManager = nullptr;
QString currentTrack, nextTrack;
};
#endif