QMediaPlayer -> Can´t get it to play
-
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(); } -
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(); -
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();@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 pathsqUrl.setUrl("file:///sdcard/Music/" + files.at(i));
-
@Flaming-Moe said in QMediaPlayer -> Can´t get it to play:
fromLocalFile
May be it´s the difference in "fromLocalFile"