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. QSound play old file
Forum Updated to NodeBB v4.3 + New Features

QSound play old file

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 3 Posters 623 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.
  • K Offline
    K Offline
    kskim
    wrote on last edited by kskim
    #1

    python 3.6 / pyside2

    my code:

    player = QSound('./temp/play.wav')
    player.play()
    while not player.isFinished():
        QApplication.processEvents()
        time.sleep(0.1)
    player.stop()
    os.remove('./temp/play.wav')
    

    in my program, receive an audio file with the name './temp/play.wav'. and play it.
    but sometimes it play old file.

    is it possible that Qsound object is not recreated and the old object is referenced?

    I check audio file received from server but it's okay.
    there is no problem with path and file downloaded from server.
    Additionally, this issue appears intermittently.

    eyllanescE 1 Reply Last reply
    0
    • K kskim

      python 3.6 / pyside2

      my code:

      player = QSound('./temp/play.wav')
      player.play()
      while not player.isFinished():
          QApplication.processEvents()
          time.sleep(0.1)
      player.stop()
      os.remove('./temp/play.wav')
      

      in my program, receive an audio file with the name './temp/play.wav'. and play it.
      but sometimes it play old file.

      is it possible that Qsound object is not recreated and the old object is referenced?

      I check audio file received from server but it's okay.
      there is no problem with path and file downloaded from server.
      Additionally, this issue appears intermittently.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @kskim please provide a minimal and reproducible example

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kskim
        wrote on last edited by
        #3
        def download_audio(audio_path):
            # download audio file from audio-file-server
            with open('./temp/play.wav', 'wb') as f:
                f.write(audio_data)
        
        class myapp:
            def play_audio():
                player = QSound('./temp/play.wav')
                player.play()
                while not player.isFinished():
                    QApplication.processEvents()
                    time.sleep(0.1)
                player.stop()
                os.remove('./temp/play.wav')
        

        when downloading an audio file from audio-file-server and playing it,
        even if I request and download another audio file and then play it, the first file is played.
        but the first file is already deleted.

        JonBJ 1 Reply Last reply
        0
        • K kskim
          def download_audio(audio_path):
              # download audio file from audio-file-server
              with open('./temp/play.wav', 'wb') as f:
                  f.write(audio_data)
          
          class myapp:
              def play_audio():
                  player = QSound('./temp/play.wav')
                  player.play()
                  while not player.isFinished():
                      QApplication.processEvents()
                      time.sleep(0.1)
                  player.stop()
                  os.remove('./temp/play.wav')
          

          when downloading an audio file from audio-file-server and playing it,
          even if I request and download another audio file and then play it, the first file is played.
          but the first file is already deleted.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @kskim

          player = QSound('./temp/play.wav')
          ...
          os.remove('./temp/play.wav')
          

          One thought is that it may not be a good idea to try to remove the file when you still have an instance of QSound() active on it. I would eliminate that by moving the deletion out of play_audio(), so it has a chance to be freed. In any case, it should not be the job of a function playing an audio file to delete that file. E.g. move the os.remove('./temp/play.wav') into download_audio() before the with open('./temp/play.wav', 'wb') as f:.

          Otherwise verify 100% that the audio_data buffer contains different bytes second time around.

          Otherwise each time round create and play play1.wav, play2.wav, play3.wav, ... instead of the same filename. Then you will know whether it's an issue about reusing a filename or not.

          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