soundplayer.h 1.23 KB
#ifndef SOUNDPLAYER_H
#define SOUNDPLAYER_H

#include <QObject>
#include <QSound>
#include <QSoundEffect>
#include <QThread>
#include <QMap>
#include <QProcess>

class SoundPlayWorker : public QObject
{
    Q_OBJECT

    bool repeat_;

public:
    explicit SoundPlayWorker();

public slots:
    void play(const QString &filename);
    void playClick();
    void setVolume(int volume);
    void repeat(const QString &filename);
    void stop();

private:
    QMap<QString, QSound *> map;
    QSound *current;
    QSoundEffect *click;
    QProcess *proc;

private slots:
    void onFinished();
};

class SoundPlayer : public QObject
{
    Q_OBJECT

    explicit SoundPlayer();
    void play(const QString &filename);
    void emitClick();
    void repeat(const QString &filename);
    void stopPlay();


    static SoundPlayer *instance;

public:
    static void playClick();
    static void playStart();
    static void playStop();
    static void playError1();
    static void playError2();
    static void repeatError1();
    static void repeatError2();
    static void stop();

signals:
    void setVolume(int);
    void operate(const QString &);
    void click();
    void operateRepeat(const QString &);
    void operateStop();
};

#endif // SOUNDPLAYER_H