how to play/stop audio file(eg. mp3 file) using multi-threads?
-
@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)?
-
@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.
-
So why don't you simply do what @jsulm suggest and use signals/slots?