Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to play music in a function until the end of the music to end the function ?
As in the title,in linux, what can i do ?
Pl45m4 last edited by
to the end of the function
You cant control that.
playwill start its own loop and return immediately to the function where it was called. So if your music file is 3mins long, the music will still play, even if the function is not executed at that moment.
You could use
QSoundEffectand mute or stop the music when you reached the end of your function.
QMultimediaPlayer::start()at the start of the method and
QMultimediaPlayer::stop()at the end, thank you.
Mentioned by you
Pl45m4 last edited by Pl45m4
But none of them ensures that the sound file reached its end, when you call
stopat the end of your function where
playwas called :)
@plalq has to either check with
isFinished()or deal with it
@Pl45m4 well, yes. Possibly I misread the title... Signal/slot relation being a backbone of Qt - I thought it's quite obvious.
Thank you both for your replies, I didn't express myself clearly, my mistake. I want to open a new thread for playing music, and when the music is finished, I can close the thread. The only way I can think of is to use QTimer to set a timer that counts down to the same amount of time as the music, and then listen to the timeout slot function to exit the thread. Is there a class that has a finished signal when the music finishes playing to do this?@artwaw @Pl45m4
Bonnie last edited by
The playing part is asynchronous. There's no need to open a thread.
@Bonnie ohhhh! thx, i found QSoundEffect::playingChanged is what i need , but it is not right now.
Kelvin Saunders Banned last edited by
This post is deleted!
hellobaby last edited by
This is also what I was looking for for my device. Music playback is currently a trend of users of smart devices.