Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Playing music in background

Playing music in background

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 4 Posters 408 Views
  • 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.
  • behruz montazeriB Offline
    behruz montazeriB Offline
    behruz montazeri
    wrote on last edited by
    #1

    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:
                self.playsoundQu(i)
    

    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()
            player.set_media(media)
            player.play()
            time.sleep(1.5)
            duration = player.get_length() / 1000
            time.sleep(duration)
    

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

    J.HilkJ jsulmJ 2 Replies Last reply
    0
    • behruz montazeriB behruz montazeri

      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:
                  self.playsoundQu(i)
      

      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()
              player.set_media(media)
              player.play()
              time.sleep(1.5)
              duration = player.get_length() / 1000
              time.sleep(duration)
      

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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @behruz-montazeri
      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++


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • behruz montazeriB behruz montazeri

        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:
                    self.playsoundQu(i)
        

        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()
                player.set_media(media)
                player.play()
                time.sleep(1.5)
                duration = player.get_length() / 1000
                time.sleep(duration)
        

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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved