File indexing completed on 2024-05-12 17:21:22

0001 /*
0002  * SPDX-FileCopyrightText: 2020-2021 Devin Lin <devin@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QAudioOutput>
0010 #include <QMediaPlayer>
0011 #include <QQmlEngine>
0012 #include <QUrl>
0013 #include <QCoreApplication>
0014 
0015 class AudioPlayer : public QMediaPlayer
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     static AudioPlayer *instance();
0021 
0022     void handleStateChange(QMediaPlayer::PlaybackState state);
0023 
0024     Q_INVOKABLE void setMediaPath(QString path);
0025     Q_INVOKABLE void setVolume(float volume);
0026 
0027 private:
0028     explicit AudioPlayer(QObject *parent = nullptr);
0029 
0030     QAudioOutput *m_audioOutput;
0031     
0032     bool wasStopped = false;
0033 };