How to temporarily empty a QMediaPlayer object?

  • Hello

    I've got a QMediaPlayer in my PyQt5-based app and I've got a situation where I want to close the current video (so it goes to black, or equivalent), wait for the user to select another video, then open it.

    The pseudocode is:

    nullMedia = QMediaContent(None)

    I'm having a problem with setting nullMedia, i.e. makng the QMediaPlayer show black. If I run (the equivalent of) the above code, then the video panel does go black. However, when I open videoFile2, the video panel stays black. videoFile2 doesn't get displayed properly.

    If I comment out the 'setMedia(nullMedia)' line, then videoFile1 remains visible, and then when videoFile2 is selected, it loads absolutely fine. So something about the setting to nullMedia is causing the QMediaPlayer to fail on future setMedia() calls.

    Please can somebody tell me what I'm doing wrong here? What's the proper way to make a QMediaPlayer object empty so it no longer contains a video file, without affecting its ability to load the next file?

  • Lifetime Qt Champion

    @donquibeats Maybe you should call on the playlist after loading videoFile2?
    Or call before setting videoFile2?

  • Thanks @jsulm for pointing me in the right direction.

    This is what worked for me:

    emptyPlaylist = QMediaPlaylist()

Log in to reply