Skip to content

Commit

Permalink
fix audio output sometimes crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
olav-st committed Feb 14, 2015
1 parent 3881413 commit b82b6fa
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions screencloud/src/audionotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ void AudioNotifier::play(QString file)
settings.endGroup();
if(soundNotifications)
{
#ifdef Q_OS_MACX
audioFile.setFileName(QString(qApp->applicationDirPath() + "/../Resources/" + file).toLocal8Bit());
#else
audioFile.setFileName(QString(qApp->applicationDirPath() + QDir::separator() + file).toLocal8Bit());
#endif
audioFile.open(QIODevice::ReadOnly);
if(!audioFile.isOpen())
{
#ifdef Q_OS_MACX
audioFile.setFileName(QString(qApp->applicationDirPath() + "/../Resources/" + file).toLocal8Bit());
#else
audioFile.setFileName(QString(qApp->applicationDirPath() + QDir::separator() + file).toLocal8Bit());
#endif
audioFile.open(QIODevice::ReadOnly);
}
//Make sure we dont try to play the wav headers
for(int i = 0; i < audioFile.size(); ++i) {
QByteArray ba = audioFile.peek(4);
Expand Down Expand Up @@ -96,11 +99,9 @@ void AudioNotifier::audioStateChanged(QAudio::State state)
{
WARNING(tr("Error while playing audio. Code: ") + QString::number(audioOutput->error()));
audioOutput->stop();
audioFile.close();
}
if(state == QAudio::IdleState)
{
audioOutput->stop();
audioFile.close();
}
}

0 comments on commit b82b6fa

Please sign in to comment.