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 temporarily empty a QMediaPlayer object?
Forum Updated to NodeBB v4.3 + New Features

How to temporarily empty a QMediaPlayer object?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 677 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.
  • D Offline
    D Offline
    donquibeats
    wrote on last edited by
    #1

    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:

    window.mediaPlayer.setMedia(QMediaContent(QUrl(videoFile1)))
    wait_for_user_to_say_they_are_done_with_videoFile1()
    nullMedia = QMediaContent(None)
    window.mediaPlayer.setMedia(nullMedia)
    user_selects_videoFile2()
    window.mediaPlayer.setMedia(QMediaContent(QUrl(videoFile2)))
    

    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?

    jsulmJ 1 Reply Last reply
    0
    • D donquibeats

      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:

      window.mediaPlayer.setMedia(QMediaContent(QUrl(videoFile1)))
      wait_for_user_to_say_they_are_done_with_videoFile1()
      nullMedia = QMediaContent(None)
      window.mediaPlayer.setMedia(nullMedia)
      user_selects_videoFile2()
      window.mediaPlayer.setMedia(QMediaContent(QUrl(videoFile2)))
      

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @donquibeats Maybe you should call https://doc.qt.io/qt-5/qmediaplaylist.html#next on the playlist after loading videoFile2?
      Or call https://doc.qt.io/qt-5/qmediaplaylist.html#clear before setting videoFile2?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        donquibeats
        wrote on last edited by
        #3

        Thanks @jsulm for pointing me in the right direction.

        This is what worked for me:

        emptyPlaylist = QMediaPlaylist()
        window.mediaPlayer.setPlaylist(emptyPlaylist)
        
        1 Reply Last reply
        1

        • Login

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