Is there a way to determine the length of an audio file? The QMediaPlayer duration prop only works for the current played file. So, searching the web, I thought that a solution could be QAudioBuffer class usage.
So, this is my attempt
void MainWindow::openmediaOnClick()
{
*filenames
= QFileDialog::getOpenFileNames(this, tr
("Open Media"),
"D:", tr
("Audio Files (*.mp3 *.wav *.ogg)"));
playlist->clear();
tracklist->setRowCount(filenames->size());
for (int i=0; i < filenames->size(); i++) {
playlist
->addMedia
(QUrl(filenames
->at
(i
)));
QAudioBuffer
*audioBuffer
(QFile(filenames
->at
(i
)));
qDebug() << audioBuffer->duration();
};
this->runPlaylist();
}
void MainWindow::openmediaOnClick()
{
*filenames = QFileDialog::getOpenFileNames(this, tr("Open Media"), "D:", tr("Audio Files (*.mp3 *.wav *.ogg)"));
playlist->clear();
tracklist->setRowCount(filenames->size());
for (int i=0; i < filenames->size(); i++) {
playlist->addMedia(QUrl(filenames->at(i)));
tracklist->setItem(i, 0, new QTableWidgetItem(QString::number(i+1)));
tracklist->setItem(i, 1, new QTableWidgetItem(filenames->at(i)));
QAudioBuffer *audioBuffer(QFile(filenames->at(i)));
qDebug() << audioBuffer->duration();
};
this->runPlaylist();
}
To copy to clipboard, switch view to plain text mode
Qt send me this error message:
error: cannot convert 'QFile' to 'QAudioBuffer*' in initialization
QAudioBuffer *audioBuffer(QFile(filenames->at(i)));
Can you help me?
Bookmarks