#ifndef INCLUDESOUNDENGINE_H #define INCLUDESOUNDENGINE_H #include #include #include #include #include #include class AsyncSound : public QObject, public std::enable_shared_from_this { Q_OBJECT public: AsyncSound() = delete; explicit AsyncSound(QString path); ~AsyncSound(); QMediaPlayer* operator->() const; private: QMediaPlayer* player; private slots: void onStateChanged(const QMediaPlayer::State& state); signals: void finished(std::shared_ptr); }; class SoundEngine : public QObject { Q_OBJECT public: static SoundEngine& getInstance() { static SoundEngine instance(nullptr); return instance; } QMediaPlayer& player() const; QMediaPlaylist& playlist() const; std::shared_ptr playAsync(QString path); private: SoundEngine() = delete; SoundEngine(const SoundEngine&) = delete; explicit SoundEngine(QObject *parent = nullptr); ~SoundEngine(); private slots: void onAsyncSoundFinished(const std::shared_ptr &sound); private: QMediaPlayer *player_; // Аудио плеер QMediaPlaylist *playlist_; // Плейлист std::set> async_sounds; // Список активных асинхронных звуков }; #endif // INCLUDESOUNDENGINE_H