how to play/stop audio file(eg. mp3 file) using multi-threads?
-
Why do you want to use it in a thread at all?
-
@opengpu said in how to play/stop audio file(eg. mp3 file) using multi-threads?:
i need to play it in a callback
There is no reason for this to play an audio file in a separate thread since it's async...
-
so should i open a new thread for QMediaPlayer. and callback-thread & mainThread both send msg to the mediaPlayer thread?? and i just use the reference/pointer of the QMediaPlayer(means the QMeidaPlayer is thread-safe & can be used at different threads at the same time)?
-
so should i open a new thread for QMediaPlayer. and callback-thread & mainThread both send msg to the mediaPlayer thread?? and i just use the reference/pointer of the QMediaPlayer(means the QMeidaPlayer is thread-safe & can be used at different threads at the same time)?
@opengpu said in how to play/stop audio file(eg. mp3 file) using multi-threads?:
so should i open a new thread for QMediaPlayer
No. As @Christian-Ehrlicher already said playing media files is ASYNCH already. Playing media files does not block your main thread -> no need for any threads, don't overengeneer the task. To pause/stop simply call pause()/stop()...
-
@opengpu said in how to play/stop audio file(eg. mp3 file) using multi-threads?:
so should i open a new thread for QMediaPlayer
No. As @Christian-Ehrlicher already said playing media files is ASYNCH already. Playing media files does not block your main thread -> no need for any threads, don't overengeneer the task. To pause/stop simply call pause()/stop()...
-
@opengpu said in how to play/stop audio file(eg. mp3 file) using multi-threads?:
is QMediaPlayer thread-safe?
No.
-
@jsulm ok. so you mean i can just play/pause/stop in both mainThread and the other thread?
i am worried about : sometimes at the same time, stop() is trigered in mainThread & play() is triggered in the other thread... -
@opengpu Why do you have two threads? If you really need two threads then simply send signals for pause/stop from the other thread and pause/stop in the main thread (where your QMediaPlayer is)...
-
So why don't you simply do what @jsulm suggest and use signals/slots?