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. Always display frame of QVideoWidget

Always display frame of QVideoWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvideowidgetqmediaplayergridlayoutlistwidget
9 Posts 2 Posters 1.9k 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.
  • J Offline
    J Offline
    James Whiteley
    wrote on last edited by
    #1

    I have a widget called ThumbnailVideoWidget which plays a short video clip with included play button and position slider widgets. I am using PySide2-5.9.0a1.

    My issues are:

    1. Initially no frames are shown in the QVideoWidget, its just a transparent background. Is there a way to initialize a QVideoWidget/QMediaPlayer with a video and display the first frame automatically?

    2. When I click play and then pause, everything plays properly but when I move my mouse off of the play button, the video goes blank/transparent again. The expected behavior would be to stop and keep on the current frame.

    Source code of widget:

    class ThumbnailVideoWidget(QtWidgets.QWidget):
    
        def __init__(self, path, parent=None):
            super(ThumbnailVideoWidget, self).__init__(parent)
            self.setup_ui()
            self.connect_signals()
            self.set_media(path)
    
    
        def setup_ui(self):
            self.media_player = QtMultimedia.QMediaPlayer(self, QtMultimedia.QMediaPlayer.VideoSurface)
            self.w_video = QtMultimediaWidgets.QVideoWidget()
            self.b_play = QtWidgets.QPushButton()
            self.b_play.setEnabled(False)
            self.b_play.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
            self.position_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
            self.position_slider.setRange(0, 0)
    
            self.media_player.setVideoOutput(self.w_video)
            self.lyt_main = QtWidgets.QVBoxLayout()
            self.lyt_main.addWidget(self.w_video)
            self.lyt_main.addWidget(self.b_play)
            self.lyt_main.addWidget(self.position_slider)
            self.setLayout(self.lyt_main)
    
    
        def connect_signals(self):
            self.position_slider.sliderMoved.connect(self.set_position)
            self.b_play.clicked.connect(self.play)
            self.media_player.stateChanged.connect(self.media_state_changed)
            self.media_player.positionChanged.connect(self.position_changed)
            self.media_player.durationChanged.connect(self.duration_changed)
    
        
        def set_media(self, path):
            self.media_player.setMedia(QtCore.QUrl.fromLocalFile(path))
            self.b_play.setEnabled(True)
    
    
        def play(self):
            if self.media_player.state() == QtMultimedia.QMediaPlayer.PlayingState:
                self.media_player.pause()
            else:
                self.media_player.play()
    
    
        def set_position(self, position):
            self.media_player.setPosition(position)
    
    
        def media_state_changed(self, state):
            if self.media_player.state() == QtMultimedia.QMediaPlayer.PlayingState:
                self.b_play.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause))
            else:
                self.b_play.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
    
    
        def position_changed(self, position):
            self.position_slider.setValue(position)
    
    
        def duration_changed(self, duration):
            self.position_slider.setRange(0, duration)
            interval = int(float(duration) / 10.0)
            self.media_player.setNotifyInterval(interval)
    
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This version of PySide2 being pretty old, I would recommend updating before digging further.

      Also, what OS are you running that on ?
      How did you install PySide2 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        This version of PySide2 being pretty old, I would recommend updating before digging further.

        Also, what OS are you running that on ?
        How did you install PySide2 ?

        J Offline
        J Offline
        James Whiteley
        wrote on last edited by
        #3

        @SGaist We built it from source a long long time ago. I'm on Windows 64-bit. I'll try upgrading PySide2 real quick and see if that fixes the issue.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          This version of PySide2 being pretty old, I would recommend updating before digging further.

          Also, what OS are you running that on ?
          How did you install PySide2 ?

          J Offline
          J Offline
          James Whiteley
          wrote on last edited by
          #4

          @SGaist Ah you know I think we would need to rebuild python27 due to MSVC for our tools. Maybe I will just try going python3/PyQt5 route and get back to you.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can install it using pip, no need to build it from scratch.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • SGaistS SGaist

              You can install it using pip, no need to build it from scratch.

              J Offline
              J Offline
              James Whiteley
              wrote on last edited by
              #6

              @SGaist The pip install for PySide2 only seems to work with python 3.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by SGaist
                #7

                Ah yes, it seems that there's indeed no Py27 per-built package for Windows.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                0
                • SGaistS SGaist

                  Ah yes, it seems that there's indeed no Py27 per-built package for Windows.

                  J Offline
                  J Offline
                  James Whiteley
                  wrote on last edited by
                  #8

                  @SGaist Just got back into this, upgrading to the latest PyQt5 w/ Python3 solved the issue.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Great !

                    The please mark the thread as solved using the "Topic Tools" button or the three doted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

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