Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Play mp3 from usb in qt 5
Forum Updated to NodeBB v4.3 + New Features

Play mp3 from usb in qt 5

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 753 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BerkayTtkB Offline
    BerkayTtkB Offline
    BerkayTtk
    wrote on last edited by
    #1

    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;
    }

    Christian EhrlicherC 1 Reply Last reply
    0
    • BerkayTtkB BerkayTtk

      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;
      }

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • BerkayTtkB Offline
        BerkayTtkB Offline
        BerkayTtk
        wrote on last edited by
        #3

        thanks ,i will check it.

        1 Reply Last reply
        0
        • BerkayTtkB Offline
          BerkayTtkB Offline
          BerkayTtk
          wrote on last edited by
          #4

          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

          jsulmJ SGaistS 2 Replies Last reply
          0
          • BerkayTtkB BerkayTtk

            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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • BerkayTtkB Offline
              BerkayTtkB Offline
              BerkayTtk
              wrote on last edited by
              #6

              I am trying to read mp3 files from usb exactly but fail

              jsulmJ 1 Reply Last reply
              0
              • BerkayTtkB BerkayTtk

                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

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                @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 working

                What exactly does driveData+filenames contain ? Print it on your console. I suspect the path is invalid.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • BerkayTtkB BerkayTtk

                  I am trying to read mp3 files from usb exactly but fail

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  BerkayTtkB 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @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...

                    BerkayTtkB Offline
                    BerkayTtkB Offline
                    BerkayTtk
                    wrote on last edited by
                    #9

                    @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.

                    jsulmJ 1 Reply Last reply
                    0
                    • BerkayTtkB BerkayTtk

                      @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.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      BerkayTtkB 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @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.

                        BerkayTtkB Offline
                        BerkayTtkB Offline
                        BerkayTtk
                        wrote on last edited by
                        #11

                        @jsulm yes, i added that too ,now working.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved