Mediaplayer plays RTSP stream from camera, how to restore connection after break?
-
Hi. I have simple QML module, which shows stream from IP-camera. It works, but if I switch off camera for some seconds, the image freeses for aproximately 20 sec, only then playbackState becomes 0, and I see a white screen. The connection doesn't come alive automaticly.
import QtQuick 2.15 import QtQml 2.15 import QtQuick.Window 2.15 import QtMultimedia 5.15 Item { MediaPlayer { id: mediaPlayer source: "rtsp://192.168.88.179:554/user=admin_password=_channel=0_stream=0.sdp?real_stream" autoPlay: true autoLoad: true videoOutput: camera_1 onError: { console.debug("onError() - error=" + error + ", errorString=" + errorString) } onPlaybackStateChanged: { console.debug("onPlaybackStateChanged() - state=" + playbackState) if(playbackState == 0) { mediaPlayer.play(); } } } VideoOutput { id: camera_1 width: 1024 height: 600 source: mediaPlayer } }Is there any way to cheer up the connection? Or I have to reload my QML module from the caller for completly restart it? Like this https://doc.qt.io/qt-6/qml-qtquick-loader.html?
I don't want to complicate program. I wrote it in Creator on Widgets. I have some QQuickWidgets in it, which twists QML code all the time. I switch between them by button. It is something like car panel.
-
Hi,
What about clearing the source value and then setting it again to the stream URL ?
-
Ok. This solution works:
onPlaybackStateChanged: { if(playbackState == 0) { source = "" source = "rtsp://192.168.88.179:554/user=admin_password=_channel=0_stream=0.sdp?real_stream" mediaPlayer.play(); } }Also, it works without source = "", if I use another login-password pare at every reconnect. It generates "source change" event too.
Now I have to find a way to fasten the playbackState reaction on actual loss of connection.