add better Sound error handling

This commit is contained in:
Stephen Birarda 2014-04-18 13:51:58 -07:00
parent e9768ca4fc
commit 6ef4e145c5
2 changed files with 15 additions and 7 deletions

View file

@ -73,15 +73,18 @@ Sound::Sound(const QUrl& sampleURL, QObject* parent) :
// QNetworkAccess manager to grab the raw audio file at the given URL // QNetworkAccess manager to grab the raw audio file at the given URL
QNetworkAccessManager *manager = new QNetworkAccessManager(this); QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
qDebug() << "Requesting audio file" << sampleURL.toDisplayString(); 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 // replace our byte array with the downloaded data
QByteArray rawAudioByteArray = reply->readAll(); 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) { void Sound::downSample(const QByteArray& rawAudioByteArray) {
// assume that this was a RAW file and is now an array of samples that are // assume that this was a RAW file and is now an array of samples that are

View file

@ -13,8 +13,7 @@
#define hifi_Sound_h #define hifi_Sound_h
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtNetwork/QNetworkReply>
class QNetworkReply;
class Sound : public QObject { class Sound : public QObject {
Q_OBJECT Q_OBJECT
@ -31,7 +30,8 @@ private:
void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray); void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);
private slots: private slots:
void replyFinished(QNetworkReply* reply); void replyFinished();
void replyError(QNetworkReply::NetworkError code);
}; };
#endif // hifi_Sound_h #endif // hifi_Sound_h