Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2240

QMediaPlayer crashes in response to drop event

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.4.2
    • PySide
    • None
    • Linux/Other display system, macOS

    Description

      I'm trying to play a video with QMediaPlayer in response to a drag and drop event, and I find that it works or doesn't work depending on where the player is instantiated.

      Below is a minimal example highlighting the issue. This works fine when EARLY = True, and gives a segfault when EARLY = False.

      Bug is reproduced on:

      • Qt 6.4.2, Python 3.11.2, Apple M2 Pro, macOS 13.2.1
      • Qt 6.4.2, Python 3.11.2, Apple Intel, macOS 10.14
      • Qt 6.4.2, Python 3.11.2, Linux Mint 21.1
      #!/usr/bin/env python3
      # encoding: utf-8
      
      import os
      import sys
      from PySide6.QtWidgets import QApplication
      from PySide6.QtCore import QUrl, qVersion
      from PySide6.QtWidgets import QMainWindow
      from PySide6.QtMultimedia import QMediaPlayer
      from PySide6.QtMultimediaWidgets import QVideoWidget
      
      # Drag and drop a video file into the window to play it
      # e.g., http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
      
      EARLY = True   # segfault when `False`
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super().__init__()
              self.resize(800, 600)
              self.setWindowTitle('Qt6 Video Player')
              self.setAcceptDrops(True)
      
              if EARLY:
                  self.player = QMediaPlayer()
      
          def dragEnterEvent(self, e):
              if e.mimeData().hasUrls():
                  e.acceptProposedAction()
      
          def dropEvent(self, e):
              paths = [os.path.abspath(url.toLocalFile())
                       for url in e.mimeData().urls()]
      
              if not EARLY:
                  self.player = QMediaPlayer()
      
              videoWidget = QVideoWidget()
              self.setCentralWidget(videoWidget)
              self.player.errorOccurred.connect(self.mediaErrorOccured)
              self.player.setVideoOutput(videoWidget)
              self.player.setSource(QUrl.fromLocalFile(paths[0]))
              self.player.play()
      
          def mediaErrorOccured(self, error, message):
              print('error:', error, message)
      
      
      if __name__ == '__main__':
          print(f'Qt version {qVersion()}')
          app = QApplication(sys.argv)
          window = MainWindow()
          window.show()
          app.exec() 

      Attachments

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            jboyce Jack Boyce
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: