Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaPlay stream does not wokk
Forum Updated to NodeBB v4.3 + New Features

QMediaPlay stream does not wokk

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bclay1297
    wrote on last edited by
    #1

    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 played

    	mMediaPlayer->setMedia(QUrl("https://stream.revma.ihrhls.com/zc1781"));
    	mMediaPlayer->setVolume(50);
    	mMediaPlayer->play();
    

    Any thoughts or suggestions would be greatly appreciated,

    Bruce

    JonBJ 1 Reply Last reply
    0
    • B bclay1297

      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 played

      	mMediaPlayer->setMedia(QUrl("https://stream.revma.ihrhls.com/zc1781"));
      	mMediaPlayer->setVolume(50);
      	mMediaPlayer->play();
      

      Any thoughts or suggestions would be greatly appreciated,

      Bruce

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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.

      ?

      1 Reply Last reply
      1
      • QtAndrewQ Offline
        QtAndrewQ Offline
        QtAndrew
        wrote on last edited by QtAndrew
        #3

        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.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bclay1297
          wrote on last edited by
          #4

          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();
          
          eyllanescE 1 Reply Last reply
          0
          • B bclay1297

            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();
            
            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by
            #5

            @bclay1297 Never use time consuming while loop in Qt. And worse if _sleep is a function that blocks the eventloop. Remove the unnecessary while loop

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            1 Reply Last reply
            2
            • B Offline
              B Offline
              bclay1297
              wrote on last edited by
              #6

              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

              JonBJ 1 Reply Last reply
              0
              • B bclay1297

                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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @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.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bclay1297
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved