QMediaPlayer
Unsolved
General and Desktop
-
Dear QTDevs,
I am struggeling with the QMediaPlayer. I can play songs and stop them. But the song has 40s and I want to use it as a notification sound. So i should only play for 8 sec and then stops. I tried some things with sleep() or delay. But it is not working and i thought there would be a way to do it more neat.Thanks a lot,
Me -
Hi
There is no PlayPart or similar. You will have to call stop on it when you want it to stop before its
actual duration.Some way could be.
Note the use of static. if you only need this in one Form
i would make QSound s a member and the function a member also.
However, this is contained in a function using a lambda for compactness.void PlayNoti(int duration = 8000) /*msec*/ { static QSound s("mysounds/bells.wav"); s.play(); QTimer::singleShot(duration, []() { s.stop(); }); }