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. QMediaPlayer crashes in response to drop event
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer crashes in response to drop event

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 293 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
    jboyce
    wrote on last edited by
    #1

    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. Am I doing something obviously wrong here?

    Details: Qt 6.4.2, Python 3.11.2, Apple M2 Pro, macOS 13.2.1

    (Background: My app allows (a variable number of) videos to be loaded simultaneously when the user drops videos, and I want each to have its own QMediaPlayer. Hence the need to instantiate the player in response to a drop event.)

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

    #!/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()
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How did you install PySide6 ?

      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 and welcome to devnet,

        How did you install PySide6 ?

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

        @SGaist I used pip as follows:

        mkdir env
        python3 -m venv env
        source env/bin/activate
        pip install PySide6
        

        Also I've observed the same crashing behavior on macOS Intel, and Linux (Mint 21.1).

        SGaistS 1 Reply Last reply
        0
        • J jboyce

          @SGaist I used pip as follows:

          mkdir env
          python3 -m venv env
          source env/bin/activate
          pip install PySide6
          

          Also I've observed the same crashing behavior on macOS Intel, and Linux (Mint 21.1).

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jboyce in that case, you should check the bug report system to see if there's something there and if not, please open a new ticket providing your example.

          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