QSound play old file
-
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. -
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. -
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. -
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.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 ofplay_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 theos.remove('./temp/play.wav')intodownload_audio()before thewith open('./temp/play.wav', 'wb') as f:.Otherwise verify 100% that the
audio_databuffer 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.