void LoginManager::mediaUploadFinished() { _uploadAudioMenuAction->setEnabled(true); QNetworkReply* reply = static_cast<QNetworkReply*>(QObject::sender()); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QNetworkReply::NetworkError e = reply->error(); reply->deleteLater(); _progressDialog->hide(); _progressDialog->reset(); if ((statusCode == 200 && reply->error() == QNetworkReply::NoError) || _progressDialog->wasCanceled()) { _mp3File->remove(); delete _mp3File; _mediaUrl = ""; emit displaySuccess(); } else if (e == QNetworkReply::RemoteHostClosedError && _uploadTryCount < MAX_UPLOAD_TRY_COUNT) { uploadMedia(); } else { qDebug() << "error uploading media" << e; QMessageBox::warning(0, tr("Upload Error"), tr("Sorry, MuseScore couldn't upload the audio file. Error %1").arg(e), QString::null, QString::null); } }
//--------------------------------------------------------- // onGetMediaUrlReply //--------------------------------------------------------- void LoginManager::onGetMediaUrlReply(QNetworkReply* reply, int code, const QJsonObject& response) { if (code == HTTP_OK) { QJsonValue urlValue = response.value("url"); if (urlValue.isString()) { _mediaUrl = urlValue.toString(); QString mp3Path = QDir::tempPath() + QString("/temp_%1.mp3").arg(qrand() % 100000); _mp3File = new QFile(mp3Path); Score* score = mscore->currentScore()->masterScore(); int br = preferences.getInt(PREF_EXPORT_MP3_BITRATE); preferences.setPreference(PREF_EXPORT_MP3_BITRATE, 128); if (mscore->saveMp3(score, mp3Path)) { // no else, error handling is done in saveMp3 _uploadTryCount = 0; uploadMedia(); } preferences.setPreference(PREF_EXPORT_MP3_BITRATE, br); } } else // TODO: handle request error properly qWarning("%s", getErrorString(reply, response).toUtf8().constData()); #if 0 disconnect(_oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onGetMediaUrlRequestReady(QByteArray))); QJsonDocument jsonResponse = QJsonDocument::fromJson(ba); QJsonObject response = jsonResponse.object(); QJsonValue urlValue = response.value("url"); if (urlValue.isString()) { _mediaUrl = response.value("url").toString(); QString mp3Path = QDir::tempPath() + QString("/temp_%1.mp3").arg(qrand() % 100000); _mp3File = new QFile(mp3Path); Score* score = mscore->currentScore()->masterScore(); int br = preferences.getInt(PREF_EXPORT_MP3_BITRATE); preferences.setPreference(PREF_EXPORT_MP3_BITRATE, 128); if (mscore->saveMp3(score, mp3Path)) { // no else, error handling is done in saveMp3 _uploadTryCount = 0; uploadMedia(); } preferences.setPreference(PREF_EXPORT_MP3_BITRATE, br); } #endif }
void Thread::run() { if(isSong == 1) { uploadMedia(); } else if(isSong == 2) { uploadActor(); } else if(isSong == 3) { ///mp3 } else if(isSong == 4) { uploadYun(); } }
void MediaUpload::sendMedia(QString jid, MediaDescriptor descriptor) { msg = FMessage(jid, true); QFile file(descriptor.localFileUri); msg.type = FMessage::MediaMessage; msg.data = descriptor.data; msg.media_size = file.size(); msg.media_wa_type = descriptor.waType; msg.media_mime_type = descriptor.contentType; msg.remote_resource = jid; msg.local_file_uri = descriptor.localFileUri; msg.media_name = generateMediaFilename(descriptor.extension); msg.media_duration_seconds = descriptor.duration; msg.live = descriptor.live; // This will be overwritten if a media upload is required with // the final URL msg.media_url = descriptor.url; // ToDo: Save tmp file for persistence sending. msg.status = FMessage::Uploading; emit readyToSendMessage(this,msg); if (descriptor.upload) { uploadMedia(); } else { msg.status = FMessage::Uploaded; emit sendMessage(this,msg); } }