Play mp3 from usb in qt 5
-
hi,
i want to play mp3 from qt5 usb but i failed can you help for an idea or example ? thanks.my usb read code;
}
QString driveInfo,drive;foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid()) { driveData=driveInfo = storage.rootPath(); }qDebug() << driveData;
} -
hi,
i want to play mp3 from qt5 usb but i failed can you help for an idea or example ? thanks.my usb read code;
}
QString driveInfo,drive;foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid()) { driveData=driveInfo = storage.rootPath(); }qDebug() << driveData;
}@BerkayTtk said in Play mp3 from usb in qt 5:
but i failed
my usb read code;
You don't read anything here - you just iterate over all mounted devices...
You should take a look into e.g. QDir to read the contents of a directory. -
QDir directory(driveData);
QStringList files = directory.entryList(QStringList() << ".mp3" << ".MP3",QDir::Files);foreach(QString filenames, files){
QList<QStandardItem *> items;
items.append(new QStandardItem(QDir(driveData+filenames).dirName()));
items.append(new QStandardItem(driveData+filenames));
m_playListModel4->appendRow(items);
m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames));
not working -
QDir directory(driveData);
QStringList files = directory.entryList(QStringList() << ".mp3" << ".MP3",QDir::Files);foreach(QString filenames, files){
QList<QStandardItem *> items;
items.append(new QStandardItem(QDir(driveData+filenames).dirName()));
items.append(new QStandardItem(driveData+filenames));
m_playListModel4->appendRow(items);
m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames));
not working@BerkayTtk said in Play mp3 from usb in qt 5:
not working
A bit more information would be good. What exactly foes not work? What does files contain?
-
QDir directory(driveData);
QStringList files = directory.entryList(QStringList() << ".mp3" << ".MP3",QDir::Files);foreach(QString filenames, files){
QList<QStandardItem *> items;
items.append(new QStandardItem(QDir(driveData+filenames).dirName()));
items.append(new QStandardItem(driveData+filenames));
m_playListModel4->appendRow(items);
m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames));
not workingHi,
@BerkayTtk said in Play mp3 from usb in qt 5:
QDir directory(driveData);
QStringList files = directory.entryList(QStringList() << ".mp3" << ".MP3",QDir::Files);foreach(QString filenames, files){
QList<QStandardItem *> items;
items.append(new QStandardItem(QDir(driveData+filenames).dirName()));
items.append(new QStandardItem(driveData+filenames));
m_playListModel4->appendRow(items);
m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames));
not workingWhat exactly does
driveData+filenamescontain ? Print it on your console. I suspect the path is invalid. -
@BerkayTtk said in Play mp3 from usb in qt 5:
I am trying to read mp3 files from usb exactly but fail
This does not provide more information.
You also did not answer the two questions I asked... -
@BerkayTtk said in Play mp3 from usb in qt 5:
I am trying to read mp3 files from usb exactly but fail
This does not provide more information.
You also did not answer the two questions I asked...@jsulm i am sorry,
here is the part that doesn't work "m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames)); " it doesn't show and play mp3 files in qdebug but I solved the problem " qstring drivedata; " I wrote this code at the beginning and it worked, thanks everybody. -
@jsulm i am sorry,
here is the part that doesn't work "m_playlist4->addMedia(QUrl::fromLocalFile(driveData+filenames)); " it doesn't show and play mp3 files in qdebug but I solved the problem " qstring drivedata; " I wrote this code at the beginning and it worked, thanks everybody.@BerkayTtk said in Play mp3 from usb in qt 5:
driveData+filenames
As @SGaist suggested: print out driveData+filenames to see what the resulting string looks like.
My guess is that there is no separator ('/') between the folder and filename. -
@BerkayTtk said in Play mp3 from usb in qt 5:
driveData+filenames
As @SGaist suggested: print out driveData+filenames to see what the resulting string looks like.
My guess is that there is no separator ('/') between the folder and filename.