QMediaPlayer.setLoops(1) finishes current loop and does two more: is it normal?
-
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 beforeEndOfMedia
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!
-
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 ?
-
@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.
-
Would it be possible to provide a minimal script that shows that behaviour ?
-
@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 :-)