PDA

View Full Version : Recording audio stream



c1223
5th November 2013, 02:07
I want to use QT to record an internet audio stream. So far I can play the stream:



player = new QMediaPlayer();
//connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
player->setMedia(QUrl("http://idobiradio.idobi.com/;stream.mp3"));
player->setVolume(50);
player->play();


However, I want to take that data and record it to an MP3. How would I do that? I've been looking at using QIODevice but can't quite work out how to extract the data stream from the media player.

Thanks

The Storm
6th November 2013, 11:55
Please check QAudioProbe (http://qt-project.org/doc/qt-5.1/qtmultimedia/qaudioprobe.html) class. The example in the documentation is using QAudioRecorder but it works the same way for QMediaPlayer. :)

c1223
6th November 2013, 18:58
I tried that however:


QAudioProbe *probe = new QAudioProbe;
connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(streamStarted(QAudioBuffer)));

probe->setSource(player);

Setting the probe's source returns false. Using the above code as the source.

The Storm
6th November 2013, 21:23
The correct way is calling setSource() before calling play(). From what you have posted I can't guess the order that you use.
If still it does not work then as mentioned in the documentation of QAudioProbe "If the media object does not support monitoring audio, this function will return false." but I hope that this is not the issue. :)

c1223
7th November 2013, 00:50
That's what I was doing.



player = new QMediaPlayer();
player->setMedia(QUrl("http://idobiradio.idobi.com/;stream.mp3"));

QAudioProbe *probe = new QAudioProbe;
connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(streamStarted(QAudioBuffer)));

if(probe->setSource(player)) {
qDebug() << "set";
} else {
qDebug() << "couldn't set";
}

player->setVolume(50);
player->play();

The Storm
7th November 2013, 08:55
Yes, that's the correct way. I'm sorry then. I don't have other clue.

c1223
8th November 2013, 22:23
So I was thinking another way of doing this would be to use the NetworkAccessManager, however I can't seem to work out what I need to do.



QNetworkRequest request(QUrl(QString("http://idobiradio.idobi.com/;stream.mp3")));


QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);

connect(networkManager, SIGNAL(readyRead), this, SLOT(streamStarted()));

request.setRawHeader(QByteArray("Icy-MetaData"), "8192");
request.setRawHeader(QByteArray("Accept"), "*/*");
request.setRawHeader(QByteArray("Connection"), "Keep-Alive");
request.setHeader(QNetworkRequest::UserAgentHeader , "WinampMPEG/5.09");

networkManager->get(request);


I'm not entirely sure what I need to put in the slot.