Unsolved 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 ?
-
@plalq Qt Multimedia should sort you out.
-
QSound::play
https://doc.qt.io/qt-5/qsound.html#play-1
to the end of the function
You cant control that.
play
will 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
QSoundEffect
and mute or stop the music when you reached the end of your function. -
@Pl45m4
QMultimediaPlayer::start()
at the start of the method andQMultimediaPlayer::stop()
at the end, thank you.Mentioned by you
QSound
also hasstop()
method. -
-
@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
-
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.
-
This post is deleted! -
This is also what I was looking for for my device. Music playback is currently a trend of users of smart devices.
-
This post is deleted! -