I am really new to Qt development as well as audio codecs. I recently found a way to play mp3 sound using QSound. I want to play it in my qt project using QAudioOutput, but there is no mp3 codec in QAudioDeviceInfo::supportedCodecs().
I tried install mp3 codec but it is still not listed in QAudioDeviceInfo::supportedCodecs(). How can I add a codec to QAudioDeviceInfo::supportedCodecs()?
By definition QAudioDeviceInfo
provides an interface to query audio devices and their functionality. Which means any codec returned by QAudioDeviceInfo::supportedCodecs()
is a codec format the device is able to play directly, and will be probably be raw audio format like pcm
. On the other hand mp3
need to go through a software decoder first, so It will not be in this list.
Take a look at the Media Player example for a reference. It should be able to play mp3 and other formats. The project should be available in the Qt source or installation directory in your machine, either under the folder demo or examples.
It seems from the source that it does lot more than just barely playing audio. So focus on the constructor of the class Player
as well as the method Player::addToPlaylist()
ps :I speak in conditional tense because I am more familiar with Qt 4 than Qt 5.
EDIT:
As long as windows media player cannot play mp3, you will not have full mp3 support in your Qt app, and the Player
example I gave you will not work either. Download some codecs in your system till Windows media player can play mp3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With