File indexing completed on 2024-06-16 05:19:38
0001 /* 0002 * Copyright 2023 by Aditya Mehra <aix.m@outlook.com> 0003 * 0004 * Licensed under the Apache License, Version 2.0 (the "License"); 0005 * you may not use this file except in compliance with the License. 0006 * You may obtain a copy of the License at 0007 * 0008 * http://www.apache.org/licenses/LICENSE-2.0 0009 * 0010 * Unless required by applicable law or agreed to in writing, software 0011 * distributed under the License is distributed on an "AS IS" BASIS, 0012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 * See the License for the specific language governing permissions and 0014 * limitations under the License. 0015 * 0016 */ 0017 0018 #ifndef AUDIOPROVIDERSERVICE_H 0019 #define AUDIOPROVIDERSERVICE_H 0020 0021 #include <QObject> 0022 #include <QUrl> 0023 #include <QAudioSink> 0024 #include <QAudioFormat> 0025 #include <QAudioDevice> 0026 #include <QMediaDevices> 0027 #include <QEventLoop> 0028 #include "audiostreamdevice.h" 0029 0030 class AudioProviderService : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 enum PlaybackState { 0036 PlayingState = 1, 0037 PausedState = 2, 0038 StoppedState = 0 0039 }; 0040 0041 enum MediaState { 0042 NoMedia = 0, 0043 LoadingMedia = 1, 0044 LoadedMedia = 2, 0045 StalledMedia = 3, 0046 BufferingMedia = 4, 0047 BufferedMedia = 5, 0048 EndOfMedia = 6, 0049 InvalidMedia = 7 0050 }; 0051 0052 explicit AudioProviderService(QObject *parent = nullptr); 0053 ~AudioProviderService(); 0054 void syncStates(); 0055 void mediaPlay(const QUrl &url); 0056 void mediaStop(); 0057 void mediaPause(); 0058 void mediaContinue(); 0059 void mediaRestart(); 0060 void mediaSeek(qint64 seekValue); 0061 0062 public Q_SLOTS: 0063 void notifyBufferingMedia(); 0064 void notifyBufferedMedia(); 0065 void notifyStalledMedia(); 0066 void notifyEndOfMedia(); 0067 void notifyInvalidMedia(); 0068 void spectrumUpdated(QVector<double> spectrum); 0069 void durationUpdated(qint64 duration); 0070 void positionUpdated(qint64 position); 0071 0072 Q_SIGNALS: 0073 int levels(double left, double right); 0074 void spectrumChanged(QVector<double> spectrum); 0075 void playBackStateChanged(AudioProviderService::PlaybackState playbackState); 0076 void mediaStateChanged(AudioProviderService::MediaState mediaState); 0077 void positionChanged(qint64 position); 0078 void durationChanged(qint64 duration); 0079 void destroyedService(); 0080 0081 private: 0082 AudioStreamDevice *m_audioStreamDevice; 0083 AudioProviderService::PlaybackState m_currentPlaybackState; 0084 AudioProviderService::MediaState m_currentMediaState; 0085 QAudioSink *m_audioSink; 0086 QAudioFormat m_format; 0087 QUrl m_currentMediaUrl; 0088 QVector<double> m_spectrum; 0089 }; 0090 0091 #endif //AUDIOPROVIDERSERVICE_H