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. How to Resolve the QMediaPlayer Resource Error?
QtWS25 Last Chance

How to Resolve the QMediaPlayer Resource Error?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 1 Posters 940 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.
  • Y Offline
    Y Offline
    YANL
    wrote on 26 Oct 2023, 13:18 last edited by
    #1

    My organisation is using Qt 6.4.3 and using the Qt Multimedia(Widgets) module. Currently, I am unable to play any non-local files (http/https/rtsp/...) using the FFmpeg backend.

    I have verified that the FFmpeg plugin loads with environment variable QT_DEBUG_PLUGINS=1.

    Here is the system environment:

    Qt Version      : 6.4.3
    Operating System: Windows 10
    Build tool      : Visual Studio 2022 (MSBuild)
    QT_MEDIA_BACKEND: "ffmpeg"
    

    I've seen a lot of examples of issues similar to mine, but with no satisfactory solution:

    Qt Forums:

    • https://forum.qt.io/topic/145002/issues-with-using-qt-multimedia-with-ffmpeg-in-qt-6-5-audio-streaming-on-macos/7
    • https://forum.qt.io/topic/135819/showing-video-from-a-rtsp-ip-camera
    • https://forum.qt.io/topic/115988/qmedia-player-not-working

    Stack Overflow:

    • https://stackoverflow.com/questions/18134724/qmediaplayer-resource-error
    • https://stackoverflow.com/questions/56156936/cant-load-music-file-with-qmediaplayer
    • https://stackoverflow.com/search?q=QMediaPlayer+resource+error

    Here is a minimum reproducible example:

    // qt headers [omitted]
    
    int main(int argc, char* argv[]) {
        // Set environment variables (also in Windows Environment Variables)
        qputenv("QT_MEDIA_BACKEND", "ffmpeg");
    
        QApplication a(argc, argv);
    
        std::array<QUrl, 2> testUrls = {{
            // Local file works:
            QUrl::fromUserInput(R"(C:\<Replace With Your Own Local MP4 file>)"),
            // Remote URL fails in Qt, but loads in ffplay and vlc:
            QUrl::fromUserInput("http://vjs.zencdn.net/v/oceans.mp4"),
        }};
    
        QComboBox *urlSelection = new QComboBox();
        for (QUrl testUrl : testUrls)
        {
            urlSelection->addItem(testUrl.toString(), testUrl);
        }
    
        QPushButton *playButton = new QPushButton();
        playButton->setText("PLAY");
    
        QVideoWidget *videoWidget = new QVideoWidget();
        videoWidget->setFixedSize(QSize(854, 480));
    
        QAudioOutput *audioOutput = new QAudioOutput();
        QMediaPlayer *mediaPlayer = new QMediaPlayer();
    
        QObject::connect(playButton, &QPushButton::clicked, [=](bool) {
            QUrl url = urlSelection->currentData().toUrl();
            mediaPlayer->setSource(url);
            mediaPlayer->setVideoOutput(videoWidget);
            mediaPlayer->setAudioOutput(audioOutput);
            mediaPlayer->play();
        });
    
        QWidget *widget = new QWidget();
        widget->setLayout(new QVBoxLayout());
        widget->layout()->addWidget(videoWidget);
        widget->layout()->addWidget(urlSelection);
        widget->layout()->addWidget(playButton);
    
        QMainWindow *mainWindow = new QMainWindow();
        mainWindow->setCentralWidget(widget);
        mainWindow->show();
    
        return a.exec();
    }
    

    The debug console produces the following log when accessing the remote url specified:

    [ DEBUG: Player Status ] QMediaPlayer::LoadingMedia
    [ DEBUG: Player Error ] QMediaPlayer::ResourceError "Could not open file"
    [ DEBUG: Player Playback ] QMediaPlayer::PlayingState
    [ DEBUG: Player Status ] QMediaPlayer::BufferedMedia
    [ DEBUG: Player Status ] QMediaPlayer::LoadedMedia
    
    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      YANL
      wrote on 26 Oct 2023, 14:24 last edited by
      #2

      I "resolved" the bug by upgrading to a later version of Qt, namely 6.6.0.

      However, this may not be possible for everyone, so I believe this remains an open question.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        YANL
        wrote on 27 Oct 2023, 09:24 last edited by
        #3

        See also:

        • https://bugreports.qt.io/browse/QTBUG-110708
        • https://bugreports.qt.io/browse/QTBUG-111910

        Qt 6.5.1 may be sufficient to resolve the bug.

        1 Reply Last reply
        0

        2/3

        26 Oct 2023, 14:24

        • Login

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