Results 1 to 2 of 2

Thread: QMediaPlayer crash using QPlaylist

  1. #1
    Join Date
    Mar 2019
    Posts
    22
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Question QMediaPlayer crash using QPlaylist

    Hello,

    so i want to run background music on loop and i searched for it on how to do it on google and i found this bit of code:
    Qt Code:
    1. playlist = new QMediaPlaylist();
    2. playlist->addMedia(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
    3. playlist->setPlaybackMode(QMediaPlaylist::Loop);
    4.  
    5. music = new QMediaPlayer();
    6. music->setPlaylist(playlist);
    7. music->play();
    To copy to clipboard, switch view to plain text mode 

    but this code crashes as soon as the first song stops playing ? (when it wants to loop)

    but doing only this works, but the problem is it won't loop the media:
    Qt Code:
    1. music = new QMediaPlayer();
    2. music->setMedia(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
    3. music->play();
    To copy to clipboard, switch view to plain text mode 

    Here is the error message:
    File_2.PNG

    More error messages:
    https://imgur.com/P0c8UKh

    If anyone knows why does this happen, please help
    Any help is appreciated !!!!
    Attached Images Attached Images
    Last edited by MongKong; 31st March 2020 at 21:03.

  2. #2
    Join Date
    Nov 2020
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QMediaPlayer crash using QPlaylist

    Hello,

    I faced the same issue recently using Qt5.12.9, before that the code you provided worked fine.
    What I actually did is... I gave up from using QMediaPlaylist and used QMediaPlayer::stateChanged signal instead.

    In your case it should be something like:
    Qt Code:
    1. music = new QMediaPlayer();
    2. music->setMedia(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
    3.  
    4. connect(music, &QMediaPlayer::stateChanged, [this](QMediaPlayer::State state) {
    5. if (state == QMediaPlayer::State::StoppedState)
    6. {
    7. music->play();
    8. }
    9. });
    10.  
    11. music->play();
    To copy to clipboard, switch view to plain text mode 

    Hope it may help.

Similar Threads

  1. QMediaPlayer crash
    By FlyDoodle in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2019, 10:56
  2. Replies: 0
    Last Post: 3rd November 2015, 18:58
  3. Timecode in QMediaPlayer
    By mkarol in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2013, 18:50
  4. Playing MP4 and FLV with QMediaPlayer
    By JasonKretzer in forum Newbie
    Replies: 2
    Last Post: 12th September 2013, 22:58
  5. QMediaPlayer problems
    By alenn.masic in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2013, 16:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.