[C++] Playing stream with QMediaPlayer app not responding
-
I using visual studio 2019 qt5.12.3 I use ffmpeg.exe to stream my pc screen and show it inside my app.
Its playing the video stream but if my stream down or stop and ill try to lets say i start ffmpeg.exe and i can see my screen in my app, then ill kill the ffmpeg.exe and try to delete or reload new url its will crash or stuck
delete QMediaPlayer;
or
QMediaPlayer->deleteLater();
and not even
QMediaPlayer->setMedia();
working if the stream stop its will crash the app or nor respond. this is my code to play the stream
void Stream::LoadStream() { QUrl StreamUrl = QUrl("https://example.com:2083/live/stream.flv"); vWidget = new QVideoWidget(this); vWidget->setObjectName("vWidget"); vPlayer = new QMediaPlayer(this, QMediaPlayer::StreamPlayback); vPlayer->setObjectName("vPlayer"); vPlayer->setVideoOutput(vWidget); vPlayer->setMedia(StreamUrl); vPlayer->play(); vWidget->show(); } void Stream::StopStream() { vWidget->deleteLater(); //vPlayer->setPosition(0); //tried but not helped vPlayer->stop(); vPlayer->deleteLater(); // this crash the app if StreamUrl stoped streaming .. delete vPlayer; // this crash the app if StreamUrl stoped streaming .. } void Stream::ChangeUrl(QString Url) { vPlayer->setMedia(QUrl(Url);); }
how i can delete or remove the player ?
-
@Bossa said in [C++] Playing stream with QMediaPlayer app not responding:
its will crush or stuck
Then use debugger please and provide stack trace after crash.
Also: why do you delete the widget and player and create new instances if you want to load new stream? -
@jsulm as i said its stuck on this vPlayer->deleteLater(); and delete vPlayer; and vPlayer->setMedia(QUrl(Url)); and vPlayer->play();
if i do only vPlayer->deleteLater(); its stuck
if i do only delete vPlayer; its stuck
if i do only vPlayer->setMedia(QUrl(Url)); its stuck
if i do only vPlayer->play(); its stucklets say like that ..
i open my app ..
i run in my cmd ffmpeg.exe to stream my screen to my rmtp server and now i have link to my stream like that https://example.com:2083/live/stream.flv
i call the function LoadStream() and its working i can see the video
now i close the cmd with the ffmpeg to stop sharescreen
the video is black ..
now if ill try to remove or to reload QMediaPlayer its stuck ..
lets say i open again the cmd and run ffmpeg and run vPlayer->play(); its stuck if ill try to reload the link vPlayer->setMedia(QUrl(Url)); its stuck ....all this happend only if i close the stream before i remove or stop the QMediaPlayer ..