mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 01:04:06 +02:00
add better Sound error handling
This commit is contained in:
parent
e9768ca4fc
commit
6ef4e145c5
2 changed files with 15 additions and 7 deletions
|
@ -73,15 +73,18 @@ Sound::Sound(const QUrl& sampleURL, QObject* parent) :
|
|||
// QNetworkAccess manager to grab the raw audio file at the given URL
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply*)),
|
||||
this, SLOT(replyFinished(QNetworkReply*)));
|
||||
|
||||
qDebug() << "Requesting audio file" << sampleURL.toDisplayString();
|
||||
manager->get(QNetworkRequest(sampleURL));
|
||||
|
||||
QNetworkReply* soundDownload = manager->get(QNetworkRequest(sampleURL));
|
||||
connect(soundDownload, &QNetworkReply::finished, this, &Sound::replyFinished);
|
||||
connect(soundDownload, SLOT(error(QNetworkReply::NetworkError)), this, SIGNAL(error(QNetworkReply::NetworkError)));
|
||||
}
|
||||
|
||||
void Sound::replyFinished(QNetworkReply* reply) {
|
||||
void Sound::replyFinished() {
|
||||
|
||||
QNetworkReply* reply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
|
||||
// replace our byte array with the downloaded data
|
||||
QByteArray rawAudioByteArray = reply->readAll();
|
||||
|
||||
|
@ -110,6 +113,11 @@ void Sound::replyFinished(QNetworkReply* reply) {
|
|||
}
|
||||
}
|
||||
|
||||
void Sound::replyError(QNetworkReply::NetworkError code) {
|
||||
QNetworkReply* reply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
qDebug() << "Error downloading sound file at" << reply->url().toString() << "-" << reply->errorString();
|
||||
}
|
||||
|
||||
void Sound::downSample(const QByteArray& rawAudioByteArray) {
|
||||
|
||||
// assume that this was a RAW file and is now an array of samples that are
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
#define hifi_Sound_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class QNetworkReply;
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
class Sound : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -31,7 +30,8 @@ private:
|
|||
void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);
|
||||
|
||||
private slots:
|
||||
void replyFinished(QNetworkReply* reply);
|
||||
void replyFinished();
|
||||
void replyError(QNetworkReply::NetworkError code);
|
||||
};
|
||||
|
||||
#endif // hifi_Sound_h
|
||||
|
|
Loading…
Reference in a new issue