playing MP3 file with QMediaPlayer make program crash

211 Views Asked by At

Im playing a mp3 file using QMediaPlayer as a background music for my program. most of times it work without any problem, but in some users system sometimes somehow it make the whole program crash without any message... I generated a dump from user system that have this problem and here is some part of it:

...

READ_ADDRESS:  0000000000000000 

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  0000000000000000

EXCEPTION_PARAMETER2:  0000000000000000

IP_ON_HEAP:  00000217f887a290
The fault address in not in any loaded module, please check your build's rebase
log at <releasedir>\bin\build_logs\timebuild\ntrebase.log for module which may
contain the address if it were loaded.

FRAME_ONE_INVALID: 1

STACK_TEXT:  
000000ec`27efe910 00000217`f887a290     : 000000ec`27efea10 00000000`00000000 00000217`f8879360 00000000`00000001 : SMM_MP4Demuxer+0x604c
000000ec`27efe918 000000ec`27efea10     : 00000000`00000000 00000217`f8879360 00000000`00000001 000000ec`27efe944 : 0x00000217`f887a290
000000ec`27efe920 00000000`00000000     : 00000217`f8879360 00000000`00000001 000000ec`27efe944 00000000`00000001 : 0x000000ec`27efea10


STACK_COMMAND:  ~7s; .ecxr ; kb

SYMBOL_NAME:  SMM_MP4Demuxer+604c

MODULE_NAME: SMM_MP4Demuxer

IMAGE_NAME:  SMM_MP4Demuxer.ax

FAILURE_BUCKET_ID:  NULL_POINTER_READ_c0000005_SMM_MP4Demuxer.ax!Unknown

OS_VERSION:  10.0.19041.1

BUILDLAB_STR:  vb_release

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 10

IMAGE_VERSION:  1.0.2010.23

FAILURE_ID_HASH:  {1f1f19f2-de50-d883-9048-8a7795f973e9}

Followup:     MachineOwner

its says that the problem is coming from SMM_MP4Demuxer Module, by looking at its name I think its something that coming from QMediaPlayer... So I wonder how can I manage situation like this..? can I still some how play the sound? or at least can I check if the user system support playing the sound and then play it? and if not just skip it? here is a minimal reproducible of my code (working):

#include <QtWidgets/qapplication.h>
#include <QWidget>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QtWidgets/QHBoxLayout>
#include <QToolButton>
#include <QStyle>

class Widget : public QWidget
{
public:
    explicit Widget(QWidget* parent = Q_NULLPTR)
        : background_sound(new QMediaPlayer(this))
    {
        setupUi();

        QMediaPlaylist* playlist = new QMediaPlaylist(this);
        playlist->addMedia(QUrl("qrc:/background_sound.mp3"));
        playlist->setPlaybackMode(QMediaPlaylist::Loop);

        background_sound->setPlaylist(playlist);
        background_sound->setVolume(70);

        connect(background_sound, &QMediaPlayer::mediaStatusChanged, this, [&](QMediaPlayer::MediaStatus status) {
            if (background_sound->error() == QMediaPlayer::NoError) {
                if (status == QMediaPlayer::LoadedMedia)
                    background_sound->play();
            }
        });

        connect(button, &QToolButton::released, this, [&]() {
            if (background_sound->state() == QMediaPlayer::PlayingState) {
                background_sound->pause();
                button->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
            }
            else if (background_sound->state() == QMediaPlayer::PausedState) {
                background_sound->play();
                button->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
            }
        });
    }
    ~Widget() = default;

private:
    QMediaPlayer* background_sound;
    QToolButton* button;
    void setupUi()
    {
        setObjectName(QStringLiteral("MainWidget"));
        setWindowTitle(tr("Test QMediaPlayer!"));
        resize(300, 300);

        auto layout = new QHBoxLayout(this);
        layout->setObjectName(QStringLiteral("layout"));

        button = new QToolButton(this);
        button->setObjectName(QStringLiteral("button"));
        button->setMinimumSize(50, 50);
        button->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); // because we are playing it at start
        layout->addWidget(button);
    }

};

int main(int argc, char* argv[])
{
    QApplication application(argc, argv);
    Widget w;
    w.show();
    return QApplication::exec();
}

if I run the program on for example a sandbox that don't have needed codecs, it will just print errors over and over again infinitely... there is no stop to it... (no crash though) enter image description here so I wonder how can I make sure if the system actually support playing the sound... and if not try not to play at all...

0

There are 0 best solutions below