-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_player.h
47 lines (36 loc) · 1.24 KB
/
audio_player.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
#ifndef AUDIO_PLAYER_H
#define AUDIO_PLAYER_H
#include <QObject>
#include <QMediaPlayer>
class AudioPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
Q_PROPERTY(qint64 duration READ duration WRITE setPosition NOTIFY durationChanged)
Q_PROPERTY(QMediaPlayer::State state READ state NOTIFY stateChanged)
public:
explicit AudioPlayer(QObject *parent = nullptr);
Q_INVOKABLE int volume() const;
Q_INVOKABLE void setVolume(int volume);
qint64 position() const;
void setPosition(qint64 position);
qint64 duration() const;
QMediaPlayer::State state() const;
public slots:
void play(const QString &filePath);
void stop();
void togglePlayback();
signals:
void trackFinished();
void stateChanged(QMediaPlayer::State state);
void durationChanged(qint64);
void positionChanged(qint64);
private slots:
void onStateChanged(QMediaPlayer::State state);
void onMediaStatusChanged(QMediaPlayer::MediaStatus state);
void onPositionChanged(qint64 position);
void onDurationChanged(qint64 duration);
private:
QMediaPlayer* m_player;
};
#endif // AUDIO_PLAYER_H