Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add mp3 codec to qt-project

Tags:

qt

audio

qt5

codec

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()?

like image 478
aswin Avatar asked Oct 21 '22 17:10

aswin


1 Answers

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.

like image 83
UmNyobe Avatar answered Oct 25 '22 18:10

UmNyobe