QMediaPlay stream does not wokk
-
I am trying to stream music from online site. The link in the code below works in VLC but not in QT
None of the methods have a return status so I can not tell if they are working but no audio is playedmMediaPlayer->setMedia(QUrl("https://stream.revma.ihrhls.com/zc1781")); mMediaPlayer->setVolume(50); mMediaPlayer->play();
Any thoughts or suggestions would be greatly appreciated,
Bruce
-
@bclay1297 said in QMediaPlay stream does not wokk:
None of the methods have a return status so I can not tell if they are working but no audio is played
I have never used
QMediaPlayer
. But if I did I would expect to utilise the standard Qt approach of attaching slots to signals, such as QMediaPlayer::error(QMediaPlayer::Error error) and QMediaPlayer::stateChanged(QMediaPlayer::State state) and QMediaPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status). Isn't that what the docs for e.g. QMediaPlayer::setMedia() mean by:Note: This function returns immediately after recording the specified source of the media. It does not wait for the media to finish loading and does not check for errors. Listen for the mediaStatusChanged() and error() signals to be notified when the media is loaded and when an error occurs during loading.
?
-
Hello, have a look into my project for a working player --> https://github.com/Christoph-Lauer/Impulse-Response-Extractor/blob/main/src/irextractor.cpp
You must replace the local file with your URL. You have to connect the signals/slots in order to debug the player. -
Thank you for your replies. I modified the code to the that shown below. I get into
ChangedStatus one time with status "loading media". It never comes out of that state. No errors are reported. This code works properly if playing a local file just not from remote stream.int QtAudioWrapper::PlayAudioFile(QString filename)
{
int status = -1;
QString errMsg;
mMediaPlayer = new QMediaPlayer;if (mMediaPlayer != NULL) { connect(mMediaPlayer, &QMediaPlayer::mediaStatusChanged, this, &QtAudioWrapper::ChangedStatus); connect( mMediaPlayer, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &QtAudioWrapper::MediaError ); mMediaPlayer->setMedia(QUrl("https://stream.revma.ihrhls.com/zc1781")); while (mMediaPlayer->mediaStatus() != QMediaPlayer::MediaStatus::LoadedMedia) {/ _sleep(10); } mMediaPlayer->setVolume(mOutputVolume); mMediaPlayer->play();
-
The while loop was added only to see if the app would com out of the Loading state. It did not . I tried the app without the loop and it had the same results. I have seen this issue reported on Stack Overflow. https://stackoverflow.com/questions/45696232/qmediaplayer-not-loading-media-and-not-emitting-mediastatuschanged-signals
indicating the problem is not a new one just an unsolved one -
@bclay1297 said in QMediaPlay stream does not wokk:
indicating the problem is not a new one just an unsolved one
I do not see anything unsolved there. The comments after both the question and the solution end with resolution.
-
Sorry - that was the wrong link I used that to get the connect information
The following link refers to a stream
https://stackoverflow.com/questions/30507317/how-do-i-play-a-stream-with-qmediaplayer