Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QMediaPlayer -> Can´t get it to play

QMediaPlayer -> Can´t get it to play

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 382 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.
  • Flaming MoeF Offline
    Flaming MoeF Offline
    Flaming Moe
    wrote on last edited by
    #1

    Hello Folks,

    I want to use QMediaplayer to play mp3 in my Android.
    I verifyed. that it in general works by trying the QT-Creator´s example project "player".

    In my own stripped down project, I can´t make it play.
    It´s very likely, that I don´t understand the concept, what is needed to play audio.

    Also I´m not sure about the path. In my filesystem the music is under "/sdcard/Music"
    In the example project I made a message Box to display the path of the added media and it shows a "File:///sdcard/Music/<filename>.mp3"
    I also tried that as an URL extension when placing pathes in the playlist.

    Currently as a quick shot all is done in the constructor of the widget of widget-project.

    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
        QUrl qUrl;
        
        //gathering all the files with ".mp3" type found in "/sdcard/Music"
        dir = QDir::toNativeSeparators("/sdcard/Music");
        QStringList filters;
        filters << "*.mp3";
        files = dir.entryList(filters, QDir::Files | QDir::NoSymLinks);
    
    
        ui->lcdNumber->display(files.count());//To verify, that there are found
        ui->plainTextEdit->setPlainText(files.at(3));//Randomly display the path of one file
    
        player = new QMediaPlayer(this);
        m_playlist = new QMediaPlaylist();
        probe = new QVideoProbe(this);// 1) do I need this for audio only?
        probe->setSource(player);// 1) do I need this for audio only?
    
        videoWidget = new QVideoWidget(this);// 2) do I need this for audio only?
        player->setVideoOutput(videoWidget);// 2) do I need this for audio only?
    
        for(unsigned int i=0; i<files.count(); i++)
        {
            //filling the found files in via URLs in the Playlist
            qUrl.clear();
            qUrl.setUrl("file:///sdcard/Music/" + files.at(i));
            m_playlist->addMedia(qUrl);
        }
    
        //Randomly read one location of the playlist if it has a fitting path
        ui->plainTextEdit_2->setPlainText(m_playlist->media(60).canonicalUrl().toString());
        player->setVolume(50);
        m_playlist->setCurrentIndex(1);// 3 do I need to do this?
        player->play();
    
    }
    

    A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

    1 Reply Last reply
    0
    • Flaming MoeF Offline
      Flaming MoeF Offline
      Flaming Moe
      wrote on last edited by
      #2

      Hm... this works....

          player = new QMediaPlayer;
      
          m_playlist = new QMediaPlaylist(player);
          player->setMedia(QUrl::fromLocalFile("/sdcard/Music/Adiemus.mp3"));
          // ...
          player->setVolume(50);
          m_playlist->setCurrentIndex(1);
          player->play();
      

      A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

      mrjjM 1 Reply Last reply
      0
      • Flaming MoeF Flaming Moe

        Hm... this works....

            player = new QMediaPlayer;
        
            m_playlist = new QMediaPlaylist(player);
            player->setMedia(QUrl::fromLocalFile("/sdcard/Music/Adiemus.mp3"));
            // ...
            player->setVolume(50);
            m_playlist->setCurrentIndex(1);
            player->play();
        
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Flaming-Moe
        Hi
        The working code is also almost the same except for no loop of the files so I would guess
        on something with the paths

        qUrl.setUrl("file:///sdcard/Music/" + files.at(i));

        1 Reply Last reply
        0
        • Flaming MoeF Offline
          Flaming MoeF Offline
          Flaming Moe
          wrote on last edited by
          #4

          @Flaming-Moe said in QMediaPlayer -> Can´t get it to play:

          fromLocalFile

          May be it´s the difference in "fromLocalFile"

          A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

          1 Reply Last reply
          1

          • Login

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