Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QMediaPlayer.setLoops(1) finishes current loop and does two more: is it normal?
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer.setLoops(1) finishes current loop and does two more: is it normal?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 1.2k Views 1 Watching
  • 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
    jeertmans
    wrote on last edited by
    #1

    Hello,

    I am playing video slides using QMediaPlayer, and some may be looping forever (setLoops(-1)) on purpose. I'd like to add a feature that terminates the current loop before playing the next slide (video). See my PR here.

    If I call setLoops(1) on a looping video, the current loop finishes, and two more loops are played before EndOfMedia is reached. Is it the expected behavior?

    To me, I'd understand that it does one more loop after setLoops(1) was called (even though I'd prefer having no more loop), but two??

    Thanks in advance!

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

      Hi,

      In the absolute, I would understand a single additional run but that would be unexpected nonetheless. More than one definitely sounds wrong.

      Which version of Qt are you using ? On which platform ?

      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

        Hi,

        In the absolute, I would understand a single additional run but that would be unexpected nonetheless. More than one definitely sounds wrong.

        Which version of Qt are you using ? On which platform ?

        J Offline
        J Offline
        jeertmans
        wrote on last edited by
        #3

        @SGaist said in QMediaPlayer.setLoops(1) finishes current loop and does two more: is it normal?:

        Hi,

        In the absolute, I would understand a single additional run but that would be unexpected nonetheless. More than one definitely sounds wrong.

        Which version of Qt are you using ? On which platform ?

        Using PySide6.5.2, Linux with X, but I could reproduce at least on 6.5.1, 6.5.3 and 6.6.0.

        Video link: https://youtu.be/u8-SifN9ILk.

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

          Would it be possible to provide a minimal script that shows that behaviour ?

          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
          1
          • SGaistS SGaist

            Would it be possible to provide a minimal script that shows that behaviour ?

            J Offline
            J Offline
            jeertmans
            wrote on last edited by
            #5

            @SGaist you can find a MWE below.

            I manage to find a fix, but to me, it's quite ugly as it needs to stop the media player (which I guess means to reload the file?) and put it back to the previous position.

            import sys
            
            from PySide6.QtCore import Qt, QUrl
            from PySide6.QtMultimedia import QMediaPlayer
            from PySide6.QtMultimediaWidgets import QVideoWidget
            from PySide6.QtWidgets import (
                QApplication,
                QMainWindow,
            )
            
            
            class MainWindow(QMainWindow):
                def __init__(self, file):
                    super().__init__()
            
                    self._player = QMediaPlayer()
                    self._video_widget = QVideoWidget()
                    self.setCentralWidget(self._video_widget)
                    self._player.setVideoOutput(self._video_widget)
                    self._player.setLoops(-1)  # Infinite loop
            
                    url = QUrl.fromLocalFile(file)
                    self._player.setSource(url)
                    self._player.play()
            
                def keyPressEvent(self, event):
                    key = event.key()
                    if key == Qt.Key_Right:
                        self._player.setLoops(1)
                        print("Set loop to 1")
                    if key == Qt.Key_Up:  # This is an ugly fix that works
                        old_position = self._player.position()
                        self._player.setLoops(1)
                        self._player.stop()
                        self._player.setPosition(old_position)
                        self._player.play()
                        print("Set loop to 1 - patched")
                    elif event.key() == Qt.Key_Left:
                        self._player.setLoops(-1)
                        self._player.play()
                        print("Set loop to infinite")
                    event.accept()
            
            
            if __name__ == "__main__":
                app = QApplication(sys.argv)
                main_win = MainWindow(file="looping.mp4")
                available_geometry = main_win.screen().availableGeometry()
                main_win.resize(available_geometry.width() / 3, available_geometry.height() / 2)
                main_win.show()
                sys.exit(app.exec())
            

            I could not attach the video file here, but can use any video where the looping effect would be visible :-)

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TimDarcet
              wrote on last edited by
              #6

              Hi,
              I still have this issue with QMediaPlayer for the same purpose, using @jeertmans great manim-slides library.
              I would like to create a smooth transition "at the end of the next loop", but again the loop runs 2 more times before stopping.
              Any idea where this could come from?
              Thanks in advance

              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