Playing audio using thread
-
@goshantry said in Playing audio using thread:
also player->deleteLater(); always crashes the application no matter where i put it
That's because player has a parent and parent deletes its children when it is deleted, so you have a double delete. Do not pass "this" to player as parent (or do not call delete later).
And why do you try to call deleteLater BEFORE you actually use it?! You should do it when you don't need it anymore.
See https://doc.qt.io/qt-5/objecttrees.html -
AFAIK, QtMM is not designed to use in separate threads (look to QMediaPlayer source code).
-
I was reading about QPointers and I tried the following
QPointer<QMediaPlayer> player = new QMediaPlayer(this); //player = new QMediaPlayer(this);
the part which I wrote in comments works fine
The part with QPointer crashes my applicationIt comes in the following function
void QMediaPlayer::setMedia(const QMediaContent &media, QIODevice *stream) { Q_D(QMediaPlayer); stop(); QMediaContent oldMedia = d->rootMedia; d->disconnectPlaylist(); d->playlist = 0; d->rootMedia = media; d->nestedPlaylists = 0; if (oldMedia != media) emit mediaChanged(d->rootMedia); if (media.playlist()) { // reset playlist to the 1st item media.playlist()->setCurrentIndex(0); d->setPlaylist(media.playlist()); } else { d->setMedia(media, stream); } }
I get the segmentation fault error and the program crashes
-