Important: Please read the Qt Code of Conduct -

Playing music in background

  • Hello.
    I want to play music in list in background and have a control on stop theme. when i play the music my Qt form doesn't response to other function. Should i implement QThread How ?

            for i in listChecked:

    and the function :

        def playsoundQu(self,filename):
            filename = "Downloads/"+filename
            vlc_instance = vlc.Instance()
            media = vlc_instance.media_new(filename)
            player = vlc_instance.media_player_new()
            duration = player.get_length() / 1000

    It works but form doen't response to other action and is somehow locked.

  • Moderators

    I don't know much about python, but my guess is, that "time.sleep" is causing the "freeze" of your Gui, as it will do in pure c++

  • Banned

    Actually the whole thing is going to freeze up your Gui because Python is linear and even if you were to create another Thread it would still process things linearly due to the GIL issue. As such anytime you are going to create an endlessly running loop you need to either shoot it off into its own multi-process (which will then have the issue if it does not self-end) or implement some means to pass back event handling to the main event thread from time to time -- the actual solution however greatly depends upon the application's purpose and use

  • Lifetime Qt Champion

    @behruz-montazeri Make player a member variable, so it does not disappear when playsoundQu finishes and then remove all the sleep() calls from playsoundQu...

Log in to reply