C++ (Qt) mf = new QFile("test.mp3"); mf->open(QIODevice::ReadOnly); m_mediaPlayer->setMedia(QMediaContent(), mf); m_mediaPlayer->setVolume(50); m_mediaPlayer->play();
void MainWindow::readBytes(){ Q_ASSERT(freply); QByteArray array = freply->readAll(); //qDebug("got %i bytes",array.size()); qint64 wrote = ffile->write(array); qDebug("wrote %lli bytes",wrote);}void MainWindow::finished(){ qDebug("finished");}void MainWindow::slotError(QNetworkReply::NetworkError){ Q_ASSERT(freply); qDebug("reply error : %s",qPrintable(freply->errorString()));}void MainWindow::on_recordAction_triggered(bool checked){ QAction * action = qobject_cast<QAction*>(sender()); Q_ASSERT(action); if(checked) { ffile = new QFile("/home/anton/sound.bin"); if(!ffile->open(QIODevice::WriteOnly)) { QMessageBox::warning(this,trUtf8("Ошибка создания файла"),trUtf8("Не удалось создать файл\n%1").arg(ffile->errorString())); delete ffile; ffile = NULL; action->setChecked(false); return; } QUrl url("http://streaming208.radionomy.com:80/abacusfm-vintage-jazz"); QNetworkRequest request(url); freply = fnetManager.get(request); connect(freply,SIGNAL(readyRead()),this,SLOT(readBytes())); connect(freply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(freply,SIGNAL(finished()),this,SLOT(finished())); fplayer.setMedia(QMediaContent(),freply); fplayer.setVolume(40); fplayer.play(); } else { if(freply) { fplayer.stop(); disconnect(freply,SIGNAL(readyRead()),this,SLOT(readBytes())); disconnect(freply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); disconnect(freply,SIGNAL(finished()),this,SLOT(finished())); freply->deleteLater(); freply = NULL; } if(ffile) { ffile->close(); delete ffile; ffile = NULL; } }}
C++ (Qt)... } else if (stream && (!stream->isReadable() || stream->isSequential())) { m_pendingTasks = 0; m_graphStatus = InvalidMedia; m_error = QMediaPlayer::ResourceError; } else {...