Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Mediaplayer plays RTSP stream from camera, how to restore connection after break?
Forum Updated to NodeBB v4.3 + New Features

Mediaplayer plays RTSP stream from camera, how to restore connection after break?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • isstarI Offline
    isstarI Offline
    isstar
    wrote on last edited by isstar
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about clearing the source value and then setting it again to the stream URL ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • isstarI Offline
        isstarI Offline
        isstar
        wrote on last edited by isstar
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved