Change from file pointer to file reference for notifications
This commit is contained in:
parent
9a097e20c9
commit
e3439fd4af
@ -56,24 +56,26 @@ void NotificationAudio::play(const QString &filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile *file = new QFile(this);
|
||||
file->setFileName(filePath);
|
||||
if (!file->open(QIODevice::ReadOnly)){
|
||||
return;
|
||||
}
|
||||
|
||||
playFile(file);
|
||||
playFile(filePath);
|
||||
}
|
||||
|
||||
void NotificationAudio::playFile(QFile *file){
|
||||
if(!m_init || !m_decoder || !m_audio || !file){
|
||||
void NotificationAudio::playFile(const QString &filePath){
|
||||
if(!m_init || !m_decoder || !m_audio){
|
||||
return;
|
||||
}
|
||||
|
||||
resetBuffers();
|
||||
|
||||
m_file = file;
|
||||
m_decoder->setSourceDevice(m_file);
|
||||
m_file.setFileName(filePath);
|
||||
if (!m_file.open(QFile::ReadOnly)){
|
||||
return;
|
||||
}
|
||||
|
||||
if(!m_file.isReadable()){
|
||||
return;
|
||||
}
|
||||
|
||||
m_decoder->setSourceDevice(&m_file);
|
||||
m_decoder->start();
|
||||
|
||||
m_state = State::Playing;
|
||||
@ -104,12 +106,8 @@ void NotificationAudio::resetBuffers() {
|
||||
}
|
||||
}
|
||||
|
||||
if(m_file){
|
||||
if(m_file->isOpen()){
|
||||
m_file->close();
|
||||
}
|
||||
delete m_file;
|
||||
m_file = nullptr;
|
||||
if(m_file.isOpen()){
|
||||
m_file.close();
|
||||
}
|
||||
|
||||
m_data.clear();
|
||||
|
@ -37,7 +37,7 @@ protected:
|
||||
qint64 writeData(const char* data, qint64 len) override;
|
||||
|
||||
private:
|
||||
QFile *m_file;
|
||||
QFile m_file;
|
||||
State m_state;
|
||||
QBuffer m_input;
|
||||
QBuffer m_output;
|
||||
@ -50,7 +50,7 @@ private:
|
||||
bool m_init;
|
||||
bool m_isDecodingFinished;
|
||||
|
||||
void playFile(QFile *file);
|
||||
void playFile(const QString &filePath);
|
||||
void resetBuffers();
|
||||
|
||||
private slots:
|
||||
|
Loading…
Reference in New Issue
Block a user