0
As the title itself says, the problem lies in removing a media from the playlist, but precisely in removing a media that the content is lower than that of the media playing at the time.
I’m already several days researching on and found nothing, went through the mind that by removing the media, automatically is reorganizing the indexes, which makes no sense to stop or skip to next media since it is being changed the playlist and not the current media.
I did a test with the VLC:
- When removing a media with lower content than that of the currently playing media: The current media continued to play.
- When removing the current media: Playback for.
How can I solve it? My project screen:
The version of Qt is 5.12.5 running on Ubuntu 19.10 64 bits. Below a Minimum, Complete and Verifiable Example:
Player pro.
QT += core gui multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h
FORMS += \
widget.ui
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget. h
#ifndef WIDGET_H
#define WIDGET_H
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_btnPlay_clicked();
void on_btnNext_clicked();
void on_btnRemove_clicked();
private:
Ui::Widget *ui;
QMediaPlayer *mPlayer;
QMediaPlaylist *mPlaylist;
};
#endif // WIDGET_H
cpp widget.
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
mPlayer = new QMediaPlayer(this);
mPlaylist = new QMediaPlaylist(mPlayer);
mPlaylist->setPlaybackMode(QMediaPlaylist::Loop);
mPlaylist->addMedia(QUrl::fromLocalFile("/home/wmsouza/Música/LINKIN PARK - IN THE END.mp3"));
mPlaylist->addMedia(QUrl::fromLocalFile("/home/wmsouza/Música/LINKIN PARK - NUMB.mp3"));
mPlaylist->addMedia(QUrl::fromLocalFile("/home/wmsouza/Música/METALLICA - FADE TO BLACK.mp3"));
mPlaylist->addMedia(QUrl::fromLocalFile("/home/wmsouza/Música/METALLICA - NOTHING ELSE MATTERS.mp3"));
mPlayer->setPlaylist(mPlaylist);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_btnPlay_clicked()
{
mPlayer->play();
}
void Widget::on_btnNext_clicked()
{
mPlayer->playlist()->next();
}
void Widget::on_btnRemove_clicked()
{
mPlaylist->removeMedia(ui->mediaIndex->text().toInt());
}
ui widget.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>220</width>
<height>102</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="btnPlay">
<property name="text">
<string>PLAY</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="btnNext">
<property name="text">
<string>PRÓXIMA</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnRemove">
<property name="text">
<string>REMOVER</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="mediaIndex"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
I haven’t been able to test yet, but did you even try to run the next before removing? Something like
void Widget::on_btnRemove_clicked()
{ on_btnNext_clicked();
 mPlaylist->removeMedia(ui->mediaIndex->text().toInt());
}
? I just want to remind you that when using another "source" for the index of the playlist, you have to remember to adjust the indices, for example if you are using aQTableWidget
you have to be careful with the index (I think you already have, I’m just talking about "peace of mind")– Guilherme Nascimento
Running the next before does not solve, the player stops or jumps the same way.. regarding adjusting the indexes ta all right.
– NoobSaibot
I thought he couldn’t stop the music that was removed and "continued", but from his last remark it seems that something else is happening.
– Guilherme Nascimento