I have a QBuffer
in RAM with a temporary wav file, and I want to let the user listen it from any point as many times as (s)he want. But, it only allows playing it once, and doesn't allow replaying it. If I play the audio from a file (QUrl.fromLocalFile
), it can replay it. What's the difference? How to fix it?
1) To play the wav file from RAM I use the following code:
data = b""
with open(fname, "rb") as file:
data = file.read()
buf = QBuffer()
buf.setData(data) #For debugging. Real buffer is filled differently.
buf.open(QIODevice.ReadOnly);
self.mediaPlayer=QMediaPlayer(self)
self.mediaPlayer.setMedia(QMediaContent(),buf)
Then, if I call self.mediaplayer.play()
, it will play the file to the end. But, all subsequent calls to self.mediaplayer.play()
have no effect. This is not what I want.
2) If I init mediaplayer from a file, with:
self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile("/home/me/myTestApp/test.wav")))
it works OK - if i call play()
after the previous playback is over, QMediaPlayer just repeats the playback.