Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qasync will cause crash when construct QMediaPlayer in Coroutine #85

Open
lovexuan opened this issue Aug 1, 2023 · 2 comments
Open
Assignees

Comments

@lovexuan
Copy link

lovexuan commented Aug 1, 2023

code example:

import asyncio
import qasync
from PySide6 import QtWidgets, QtMultimedia, QtMultimediaWidgets
app = QtWidgets.QApplication([])
loop = qasync.QEventLoop(app)
asyncio.set_event_loop(loop)
class VideoItemWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setLayout(QtWidgets.QVBoxLayout())
        asyncio.ensure_future(self.init())
    async def init(self):
        self.player = QtMultimedia.QMediaPlayer()
        self.player.setLoops(QtMultimedia.QMediaPlayer.Loops.Infinite)
        self.player.setSource('XXX.mp4')
        self.preview_widget = QtMultimediaWidgets.QVideoWidget()
        self.preview_widget.setMinimumSize(800, 600)
        self.player.setVideoOutput(self.preview_widget)
        self.layout().addWidget(self.preview_widget)
        self.player.mediaStatusChanged.connect(self.play)
    def play(self):
        self.player.play()
w = VideoItemWidget()
w.show()
loop.run_forever()

This code is work on native PySide6

from PySide6 import QtWidgets, QtMultimedia, QtMultimediaWidgets
class VideoItemWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.player = QtMultimedia.QMediaPlayer()
        self.player.setLoops(QtMultimedia.QMediaPlayer.Loops.Infinite)
        self.player.setSource('XXX.mp4')
        self.preview_widget = QtMultimediaWidgets.QVideoWidget()
        self.preview_widget.setMinimumSize(800, 600)
        self.player.setVideoOutput(self.preview_widget)
        self.setLayout(QtWidgets.QVBoxLayout())
        self.layout().addWidget(self.preview_widget)
        self.player.mediaStatusChanged.connect(self.play)
    def play(self):
        self.player.play()
app = QtWidgets.QApplication([])
w = VideoItemWidget()
w.show()
app.exec()

I want to construct it in Coroutine because I have a lot of video to preview, so I want use async/await to optimize user experience

@hosaka
Copy link
Collaborator

hosaka commented Oct 3, 2023

Cannot reproduce, works ok using windows, python3.11 and pyside6.5.2. Can you be more specific about your environment and versions perhaps?
image

@hosaka hosaka self-assigned this Oct 3, 2023
@lovexuan
Copy link
Author

lovexuan commented Nov 30, 2023

Cannot reproduce, works ok using windows, python3.11 and pyside6.5.2. Can you be more specific about your environment and versions perhaps? image

Sorry for reply late.

I'm using MacBook Pro (M1 32GB), macOS Ventura 13.5.2, PySide6.4.2, python 3.9.13.

And yes, when I find a Windows machine with PySdie6.4.2 & python 3.9.13, it works fine. So I guess this bug related to system platform.

20231130-155426.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants