2019-10-08 14:33:38 -04:00
|
|
|
#include "NotificationAudio.h"
|
2019-10-16 22:28:45 -04:00
|
|
|
#include "WaveFile.h"
|
2019-10-08 14:33:38 -04:00
|
|
|
|
|
|
|
|
2019-10-15 13:52:30 -04:00
|
|
|
NotificationAudio::NotificationAudio(QObject *parent):
|
|
|
|
QObject(parent)
|
2019-10-08 14:33:38 -04:00
|
|
|
{
|
2019-10-15 13:52:30 -04:00
|
|
|
m_stream = new SoundOutput();
|
2019-10-16 22:28:45 -04:00
|
|
|
//m_decoder = new AudioDecoder(this);
|
|
|
|
m_file = new WaveFile(this);
|
2019-10-08 14:33:38 -04:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:26:17 -04:00
|
|
|
NotificationAudio::~NotificationAudio(){
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-10-15 13:52:30 -04:00
|
|
|
void NotificationAudio::setDevice(const QAudioDeviceInfo &device, unsigned channels, unsigned msBuffer){
|
2019-10-16 22:28:45 -04:00
|
|
|
m_device = device;
|
|
|
|
m_channels = channels;
|
|
|
|
m_msBuffer = msBuffer;
|
2019-10-15 13:52:30 -04:00
|
|
|
m_stream->setFormat(device, channels, msBuffer);
|
2019-10-16 22:28:45 -04:00
|
|
|
//m_decoder->init(m_stream->format());
|
2019-10-08 14:33:38 -04:00
|
|
|
}
|
|
|
|
|
2019-10-12 14:12:16 -04:00
|
|
|
void NotificationAudio::play(const QString &filePath){
|
2019-10-16 22:28:45 -04:00
|
|
|
//m_decoder->start(filePath);
|
|
|
|
//m_stream->restart(m_decoder);
|
|
|
|
if(m_file->isOpen()){
|
|
|
|
m_file->close();
|
|
|
|
}
|
|
|
|
if(m_file->open(filePath)){
|
|
|
|
m_file->seek(0);
|
|
|
|
m_stream->setDeviceFormat(m_device, m_file->fileFormat(), m_channels, m_msBuffer);
|
|
|
|
m_stream->restart(m_file);
|
|
|
|
}
|
2019-10-08 14:33:38 -04:00
|
|
|
}
|
|
|
|
|
2019-10-15 13:52:30 -04:00
|
|
|
void NotificationAudio::stop(){
|
2019-10-16 22:28:45 -04:00
|
|
|
//m_decoder->stop();
|
2019-10-15 13:52:30 -04:00
|
|
|
m_stream->stop();
|
2019-10-16 22:28:45 -04:00
|
|
|
|
|
|
|
if(m_file->isOpen()){
|
|
|
|
m_file->close();
|
|
|
|
}
|
2019-10-11 23:34:31 -04:00
|
|
|
}
|