I am creating media player with qt5. Code below works fine ( it open file dialog, load one song and play it after loading) but it can't play some MP3 files. These files are not damaged or something like this, I can open them with other media players. I noticed that the most of them are larger than 20 mB. Please help me if you find the solution.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QDebug>
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&player, &QMediaPlayer::mediaStatusChanged,
this, [&](QMediaPlayer::MediaStatus status){
if(status == QMediaPlayer::LoadedMedia) //play if loaded
player.play();
});
connect(&player , QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), // notify about errors
[=](QMediaPlayer::Error error){
if (error==QMediaPlayer::ResourceError)
qDebug("resource");
if (error==QMediaPlayer::FormatError)
qDebug("format");
if (error==QMediaPlayer::AccessDeniedError)
qDebug("acces");
if (error==QMediaPlayer::ServiceMissingError)
qDebug("service");
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{ QString file= QFileDialog::getOpenFileName(); //select file
player.setMedia(QUrl::fromLocalFile(file)); // load
}