-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
None
-
5.9.3, 5.12.3
-
None
-
Windows 10, Qt Creator 4.9.0, Qt 5.12.3 (64 & 32 bits), MinGW 7.3.0 (64 & 32 bits)
On Windows, a QMediaPlayer object can't play some mp3 files and the file duration isn't good.
I use MinGW 7.3.0 (64 & 32 bits).
This error has been present since Qt 5.9.3.
I've found a solution that doesn't work everytime, it's to re-encode the file with ffmpeg:
ffmpeg -i not_working.mp3 -c:a libmp3lame -q:a 3 -vn working.mp3 -y
Here is the source code (only the essential part):
mainwindow.h:
#include <QMediaPlayer> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { private: QMediaPlayer *playerBackground; };
mainwindow.cpp:
playerBackground->setMedia(QUrl(QStringLiteral("C:/Users/Smathi/Desktop/not played.mp3"))); playerBackground->play(); qDebug() << "Current media" << playerBackground->currentMedia().canonicalUrl().toString(); qDebug() << "Song status:\t" << playerBackground->mediaStatus(); qDebug() << "Song error:\t" << playerBackground->error(); qDebug() << "State:\t" << playerBackground->state(); qDebug() << "isAudioAvailable?:\t" << playerBackground->isAudioAvailable(); qDebug() << "isAvailable?:\t" << playerBackground->isAvailable(); qDebug() << "Buffer Status:\t" << playerBackground->bufferStatus(); qDebug() << "Volume:\t" << playerBackground->volume(); qDebug() << "isMetaDataAvailable?:\t" << playerBackground->isMetaDataAvailable(); qDebug() << "isSeekable?:\t" << playerBackground->isSeekable(); qDebug() << "supportedAudioRoles:\t" << playerBackground->supportedAudioRoles(); qDebug() << "duration:\t" << playerBackground->duration(); QTime total(0, 0, 0, 0); total = total.addMSecs(int(playerBackground->duration())); QString totalTime(QString::number(total.minute()) + ":" + QString::number(total.second())); qDebug() << "totalTime:\t" << totalTime;
Here is the results:
Current media: "file:///C:/Users/Smathi/Desktop/not played.mp3" Song status: QMediaPlayer::BufferedMedia Song error: QMediaPlayer::NoError State: QMediaPlayer::PlayingState isAudioAvailable?: false isAvailable?: true Buffer Status: 0 Volume: 100 isMetaDataAvailable?: true isSeekable?: false supportedAudioRoles: () duration: 0 totalTime: "0:0"
So, the file ("not played.mp3") isn't played and no sound is available even if the volume is at maximum, and duration equal 0. When the file is re-encoded ("wrong time.mp3"), there is sound available but the duration is wrong (07:07 instead of 02:55).
Everything is working on Ubuntu and Android but not Windows (10).