js8call/NotificationAudio.cpp

46 lines
1.1 KiB
C++
Raw Normal View History

2019-10-08 14:33:38 -04:00
#include "NotificationAudio.h"
#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();
//m_decoder = new AudioDecoder(this);
m_file = new WaveFile(this);
2019-10-08 14:33:38 -04:00
}
NotificationAudio::~NotificationAudio(){
stop();
}
2019-10-15 13:52:30 -04:00
void NotificationAudio::setDevice(const QAudioDeviceInfo &device, unsigned channels, unsigned msBuffer){
m_device = device;
m_channels = channels;
m_msBuffer = msBuffer;
2019-10-15 13:52:30 -04:00
m_stream->setFormat(device, channels, msBuffer);
//m_decoder->init(m_stream->format());
2019-10-08 14:33:38 -04:00
}
void NotificationAudio::play(const QString &filePath){
//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(){
//m_decoder->stop();
2019-10-15 13:52:30 -04:00
m_stream->stop();
if(m_file->isOpen()){
m_file->close();
}
}