Qt Android MediaPlayer for .mp3 files not working
-
Hey there :D
I am almost done with porting my app from Qt5.15.17 QMake to Qt6.9.1 CMake :DDD
Last thing I noticed is that for some reason playing an .mp3 sound file does not work anymore :/Previously there were no problems,
but after switching to the new version I receive output likeI/qt.multimedia.ffmpeg(30077): Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later ... W/AudioCapabilities(30077): Unsupported mime audio/ac4 W/AudioCapabilities(30077): Unsupported mime audio/x-ima W/AudioCapabilities(30077): Unsupported mime audio/eac3-joc W/AudioCapabilities(30077): Unsupported mime audio/evrc W/AudioCapabilities(30077): Unsupported mime audio/mpeg-L1 W/AudioCapabilities(30077): Unsupported mime audio/mpeg-L2 W/AudioCapabilities(30077): Unsupported mime audio/qcelp W/AudioCapabilities(30077): Unsupported mime audio/x-ms-wma W/AudioCapabilities(30077): Unsupported mime audio/evrc W/AudioCapabilities(30077): Unsupported mime audio/qcelp W/VideoCapabilities(30077): Unrecognized profile 4 for video/hevc W/VideoCapabilities(30077): Unsupported mime video/mp43 W/VideoCapabilities(30077): Unrecognized profile/level 1/32 for video/mp4v-es W/VideoCapabilities(30077): Unrecognized profile/level 32768/2 for video/mp4v-es W/VideoCapabilities(30077): Unrecognized profile/level 32768/64 for video/mp4v-es W/VideoCapabilities(30077): Unsupported mime video/wvc1
on startup,
and when trying to play my set .mp3 file just:W/ ( 8481): 273 - 2 2025-06-25 15:31:34.397 QAudioSink::start: QAudioFormat not supported by QAudioDevice >> :0 ()
Why is that? The Android device I am using is the same as before and this worked perfectly using Qt5.15.
I put some code in my main.cpp to print supported formats like
QAudioDevice device = QMediaDevices::defaultAudioOutput(); qDebug() << "Supported sample formats:"; for (auto fmt : device.supportedSampleFormats()) qDebug() << " " << fmt; QAudioFormat format = device.preferredFormat(); qDebug() << "Sample rate:" << format.sampleRate(); qDebug() << "Channel count:" << format.channelCount(); qDebug() << "Sample format:" << format.sampleFormat();
and received this output:
D/default (30077): Supported sample formats:
D/default (30077): Int16
D/default (30077): Sample rate: 48000
D/default (30077): Channel count: 2
D/default (30077): Sample format: Int16Because I did not find a real solution to this problem I just converted my .mp3 file to a .wav file which seems to work, but has an 10 times increased file size that also is reflected in the resulting apk/aab binary :/
Is anyone aware of a solution that allows me to continue playing .mp3 files on my Android device? This also works fine on iOS and macOS builds
-
Ah I forgot, in my root project CMakeLists I just add Multimedia package to link against:
find_package(Qt6 REQUIRED COMPONENTS Quick Qml QuickControls2 ... Multimedia) target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Concurrent Qt::Qml Qt::Quick Qt::QuickControls2 ... Qt::Multimedia )
For iOS I needed to add
# Add FFMpeg lib for MediaPlayer support qt_add_ios_ffmpeg_libraries(${PROJECT_NAME})
for audio to work at all, macOS does not need any additional stuff
So maybe there is some dependency for Android that I am just missing?
-
@MarcoDC If gstreamer(you may use FFmpeg) build for Android is downloaded, the libs and plugins are static and can not be linked for commercial use. What I did was to build all gstreamer stuff into a single dynamic lib. Very messy! But if your app is not commercial, you can simply link static ones to your app.