Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Keep Checking for Live Video Stream
Forum Updated to NodeBB v4.3 + New Features

Keep Checking for Live Video Stream

Scheduled Pinned Locked Moved Solved Qt for Python
16 Posts 4 Posters 1.3k 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.
  • V Offline
    V Offline
    VIDYUL SHAH
    wrote on last edited by
    #1

    Hello Community,
    I'm currently facing an issue with my program's ability to continuously check for a live video stream from my server. At present, when the program starts, it checks if there's a stream available from a given URL. If not, it displays an error indicating that the media is stopped. However, once I connect my Ethernet cable, it fails to recognize and restart the media stream. It also doesn't continue to check if the URL is streaming the video.
    How can I modify my current code to address this? What additions should I make to ensure it continuously checks for the stream and displays an error until the live video stream starts?
    Here is my code:

    #!/usr/bin/env python3
    
    import os, sys, time
    from PyQt5 import QtWidgets, QtCore
    from PyQt5.QtCore import QLibraryInfo, pyqtSignal, pyqtSlot, QUrl, QTimer, QTime, QDate, QThread
    from PyQt5.QtWidgets import QDialog, QApplication, QMainWindow
    from PyQt5.uic import loadUi
    from PyQt5.QtGui import QImage
    from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
    
    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
        QLibraryInfo.PluginsPath
    )
    
    class VideoStream(QDialog):
        ImageUpdate = pyqtSignal(QImage)
        
        def __init__(self):
            super(VideoStream, self).__init__()
            loadUi('VideoStream.ui', self)
            try:
                self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                self.media_player.setVideoOutput(self.video_label)
    
                media_content = QMediaContent(QUrl("rtsp://127.0.0.1:5000/test"))
                self.media_player.setMedia(media_content)
    
                self.timer = QTimer(self)
                #self.timer.timeout.connect(self.update_video_label)
                self.timer.start(0)  # Set the update interval in milliseconds
    
                self.media_player.stateChanged.connect(self.on_state_changed)
                self.media_player.play()
            except Exception as e:
                print(e)
            
            
        def on_state_changed(self, state):
            if state == QMediaPlayer.StoppedState:
                print("Media player stopped")
    
    if __name__=='__main__':
        app=QApplication(sys.argv)
        mainwindow=VideoStream()
        widget=QtWidgets.QStackedWidget()
        widget.addWidget(mainwindow)
        widget.show()
        app.exec_()
    

    Case 1 - Output when initially I don't connect the Ethernet cable and start the UI:
    Media player stopped
    Error: "Could not open resource for reading and writing."
    Case 2 - Output when I connect the Ethernet cable and then start the UI and at later stage remove the Ethernet Cable and Plug it Again (But in this case the streaming doesn't start again):
    Warning: "Error sending UDP packets"
    Warning: "Error sending UDP packets"
    Warning: "Error sending UDP packets"
    Media player stopped
    Error: "Could not read from resource."

    JoeCFDJ 1 Reply Last reply
    0
    • JonBJ JonB

      @VIDYUL-SHAH said in Keep Checking for Live Video Stream:

      using "start a timer 9n failure and try to restart the media player" that you suggested

      That was @SGaist. Anyway, he suggests connect a slot to QMediaPlayer.error() signal. In the slot set off a QTimer.singleShot() which does a self.media_player.play() (or maybe the self.media_player.setMedia(media_content) again too, I don't know), probably with increasing values for the single shot timeout so it does not fire too often. That is the gist, obviously you need to cease to do this after (a) the player has started successfully in case it then gets a later error or (b) a certain amount of time has expired without success, else you will be doing this forever.

      V Offline
      V Offline
      VIDYUL SHAH
      wrote on last edited by VIDYUL SHAH
      #11

      @JonB This what I have written. I have to put a label giving the status of video sream connected or disconnected. According to current logic it labelsetText switches between connected and disconnected. Is there any other kind of logic that could be used and this problem also is solved.

      class VideoStream(QDialog):
          ImageUpdate = pyqtSignal(QImage)
          
          def __init__(self):
              super(VideoStream, self).__init__()
              loadUi('VideoStream.ui', self)
              self.media_url = "rtsp://127.0.0.1:5000/test"
              self.initialize_media_player()
          def initialize_media_player(self):
              try:
                  self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                  self.media_player.setVideoOutput(self.video_label)
                  media_content = QMediaContent(QUrl(self.media_url))
                  self.media_player.setMedia(media_content)
      
                  self.timer = QTimer(self)
                  self.timer.timeout.connect(self.check_stream)
                  self.timer.start(10)  # Check stream every second
      
                  self.media_player.stateChanged.connect(self.on_state_changed)
                  self.media_player.play()
              except Exception as e:
                  print(e)
              
          def check_stream(self):
              if self.media_player.state() == QMediaPlayer.StoppedState:
                  self.initialize_media_player()
          
          def on_state_changed(self, state):
              if state == QMediaPlayer.PlayingState:
                  print("Media player Playing")
              else:
                  print("Media player stopped")
      
      JonBJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        You are breaking the connection so you have to establish a new one. One possible thing you can do is to start a timer 9n failure and try to restart the media player using an exponential value for the timer as there's no need to spam the connection if the network is down.

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

        V 2 Replies Last reply
        1
        • SGaistS SGaist

          Hi,

          You are breaking the connection so you have to establish a new one. One possible thing you can do is to start a timer 9n failure and try to restart the media player using an exponential value for the timer as there's no need to spam the connection if the network is down.

          V Offline
          V Offline
          VIDYUL SHAH
          wrote on last edited by
          #3

          @SGaist Didn't understand this timer concept. Could you explain this please

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            You are breaking the connection so you have to establish a new one. One possible thing you can do is to start a timer 9n failure and try to restart the media player using an exponential value for the timer as there's no need to spam the connection if the network is down.

            V Offline
            V Offline
            VIDYUL SHAH
            wrote on last edited by
            #4

            @SGaist Basically I want to do is error handling that is the connection is established or not established so it will keel checking for connection and display error message until the connection is established.
            I tried to use enum QMediaPlayer::Error , enum QMediaPlayer::MediaStatus and enum QMediaPlayer::State but no luck in finding the appropriate solution

            JonBJ 1 Reply Last reply
            0
            • V VIDYUL SHAH

              @SGaist Basically I want to do is error handling that is the connection is established or not established so it will keel checking for connection and display error message until the connection is established.
              I tried to use enum QMediaPlayer::Error , enum QMediaPlayer::MediaStatus and enum QMediaPlayer::State but no luck in finding the appropriate solution

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #5

              @VIDYUL-SHAH
              If you want to "keep checking something" then as @SGaist suggested you should use a QTimer to repeatedly try that (establishing connection). I don't think you get a signal for "Ethernet cable plugged in/network available". And then he also suggested to adjust the time on the timer so that it does not re-fire too rapidly.

              V 1 Reply Last reply
              0
              • V VIDYUL SHAH

                Hello Community,
                I'm currently facing an issue with my program's ability to continuously check for a live video stream from my server. At present, when the program starts, it checks if there's a stream available from a given URL. If not, it displays an error indicating that the media is stopped. However, once I connect my Ethernet cable, it fails to recognize and restart the media stream. It also doesn't continue to check if the URL is streaming the video.
                How can I modify my current code to address this? What additions should I make to ensure it continuously checks for the stream and displays an error until the live video stream starts?
                Here is my code:

                #!/usr/bin/env python3
                
                import os, sys, time
                from PyQt5 import QtWidgets, QtCore
                from PyQt5.QtCore import QLibraryInfo, pyqtSignal, pyqtSlot, QUrl, QTimer, QTime, QDate, QThread
                from PyQt5.QtWidgets import QDialog, QApplication, QMainWindow
                from PyQt5.uic import loadUi
                from PyQt5.QtGui import QImage
                from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
                
                os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
                    QLibraryInfo.PluginsPath
                )
                
                class VideoStream(QDialog):
                    ImageUpdate = pyqtSignal(QImage)
                    
                    def __init__(self):
                        super(VideoStream, self).__init__()
                        loadUi('VideoStream.ui', self)
                        try:
                            self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                            self.media_player.setVideoOutput(self.video_label)
                
                            media_content = QMediaContent(QUrl("rtsp://127.0.0.1:5000/test"))
                            self.media_player.setMedia(media_content)
                
                            self.timer = QTimer(self)
                            #self.timer.timeout.connect(self.update_video_label)
                            self.timer.start(0)  # Set the update interval in milliseconds
                
                            self.media_player.stateChanged.connect(self.on_state_changed)
                            self.media_player.play()
                        except Exception as e:
                            print(e)
                        
                        
                    def on_state_changed(self, state):
                        if state == QMediaPlayer.StoppedState:
                            print("Media player stopped")
                
                if __name__=='__main__':
                    app=QApplication(sys.argv)
                    mainwindow=VideoStream()
                    widget=QtWidgets.QStackedWidget()
                    widget.addWidget(mainwindow)
                    widget.show()
                    app.exec_()
                

                Case 1 - Output when initially I don't connect the Ethernet cable and start the UI:
                Media player stopped
                Error: "Could not open resource for reading and writing."
                Case 2 - Output when I connect the Ethernet cable and then start the UI and at later stage remove the Ethernet Cable and Plug it Again (But in this case the streaming doesn't start again):
                Warning: "Error sending UDP packets"
                Warning: "Error sending UDP packets"
                Warning: "Error sending UDP packets"
                Media player stopped
                Error: "Could not read from resource."

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #6

                @VIDYUL-SHAH I guess Qt Multimedia may not have the mechanism to check if streaming is running or stopped.

                Onvif is a tool to detect which URLs are available in the network. Nowadays, I guess all cameras are onvif compatible.

                If you use gstreamer, you can check the gap of two coming frames with a timer. If the gap is more than a few seconds(you decide, 2, 3, or 4s), it can mean streaming is broken.

                FFmpeg may have similar function.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @VIDYUL-SHAH
                  If you want to "keep checking something" then as @SGaist suggested you should use a QTimer to repeatedly try that (establishing connection). I don't think you get a signal for "Ethernet cable plugged in/network available". And then he also suggested to adjust the time on the timer so that it does not re-fire too rapidly.

                  V Offline
                  V Offline
                  VIDYUL SHAH
                  wrote on last edited by
                  #7

                  @JonB https://doc.qt.io/qt-5/qmediaplayer.html#setMedia
                  I got this link from one of the qt forum where I read on gstreamer. SO what I have done is that from one of my pc the video data is coming as a gstreamed data at url ''rtsp://127.0.0.1:5000/test". Do I need to directly use this link or should I write gstream pile? Then I also read to keep listening for the mediaStatusChanged() and error() signals. How can I use these to check if the streaming is stopped or not using "start a timer 9n failure and try to restart the media player" that you suggested . Could you please elaborate.
                  To be honest I just copied this

                  def on_state_changed(self, state):
                         if state == QMediaPlayer.StoppedState:
                             print("Media player stopped")
                  

                  from one of the github repo but didn't understand how it works.
                  @JoeCFD as you suggested, is it possible to check check gaps in frames could you share some links please. I couldn't find any related stuff. Maybe I searched the wrong way.

                  JoeCFDJ 1 Reply Last reply
                  0
                  • JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #8

                    @VIDYUL-SHAH said in Keep Checking for Live Video Stream:

                    using "start a timer 9n failure and try to restart the media player" that you suggested

                    That was @SGaist. Anyway, he suggests connect a slot to QMediaPlayer.error() signal. In the slot set off a QTimer.singleShot() which does a self.media_player.play() (or maybe the self.media_player.setMedia(media_content) again too, I don't know), probably with increasing values for the single shot timeout so it does not fire too often. That is the gist, obviously you need to cease to do this after (a) the player has started successfully in case it then gets a later error or (b) a certain amount of time has expired without success, else you will be doing this forever.

                    V 1 Reply Last reply
                    0
                    • V VIDYUL SHAH

                      @JonB https://doc.qt.io/qt-5/qmediaplayer.html#setMedia
                      I got this link from one of the qt forum where I read on gstreamer. SO what I have done is that from one of my pc the video data is coming as a gstreamed data at url ''rtsp://127.0.0.1:5000/test". Do I need to directly use this link or should I write gstream pile? Then I also read to keep listening for the mediaStatusChanged() and error() signals. How can I use these to check if the streaming is stopped or not using "start a timer 9n failure and try to restart the media player" that you suggested . Could you please elaborate.
                      To be honest I just copied this

                      def on_state_changed(self, state):
                             if state == QMediaPlayer.StoppedState:
                                 print("Media player stopped")
                      

                      from one of the github repo but didn't understand how it works.
                      @JoeCFD as you suggested, is it possible to check check gaps in frames could you share some links please. I couldn't find any related stuff. Maybe I searched the wrong way.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by
                      #9

                      @VIDYUL-SHAH take a look at the source code of qgroundcontrol for this.

                      V 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @VIDYUL-SHAH take a look at the source code of qgroundcontrol for this.

                        V Offline
                        V Offline
                        VIDYUL SHAH
                        wrote on last edited by VIDYUL SHAH
                        #10

                        @JoeCFD Ty for the suggestion but it went all over my head. Except a few lines, I couldn't understand the rest as it is a very big code.
                        Just keeping the link here if someone reading this thread might want to get help from it.
                        https://github.com/mavlink/qgroundcontrol/blob/master/src/VideoReceiver/GstVideoReceiver.cc
                        @JonB @SGaist Sorry for that, actually after reading all suggestions and trying to reply all of them, confused me.

                        1 Reply Last reply
                        0
                        • JonBJ JonB

                          @VIDYUL-SHAH said in Keep Checking for Live Video Stream:

                          using "start a timer 9n failure and try to restart the media player" that you suggested

                          That was @SGaist. Anyway, he suggests connect a slot to QMediaPlayer.error() signal. In the slot set off a QTimer.singleShot() which does a self.media_player.play() (or maybe the self.media_player.setMedia(media_content) again too, I don't know), probably with increasing values for the single shot timeout so it does not fire too often. That is the gist, obviously you need to cease to do this after (a) the player has started successfully in case it then gets a later error or (b) a certain amount of time has expired without success, else you will be doing this forever.

                          V Offline
                          V Offline
                          VIDYUL SHAH
                          wrote on last edited by VIDYUL SHAH
                          #11

                          @JonB This what I have written. I have to put a label giving the status of video sream connected or disconnected. According to current logic it labelsetText switches between connected and disconnected. Is there any other kind of logic that could be used and this problem also is solved.

                          class VideoStream(QDialog):
                              ImageUpdate = pyqtSignal(QImage)
                              
                              def __init__(self):
                                  super(VideoStream, self).__init__()
                                  loadUi('VideoStream.ui', self)
                                  self.media_url = "rtsp://127.0.0.1:5000/test"
                                  self.initialize_media_player()
                              def initialize_media_player(self):
                                  try:
                                      self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                                      self.media_player.setVideoOutput(self.video_label)
                                      media_content = QMediaContent(QUrl(self.media_url))
                                      self.media_player.setMedia(media_content)
                          
                                      self.timer = QTimer(self)
                                      self.timer.timeout.connect(self.check_stream)
                                      self.timer.start(10)  # Check stream every second
                          
                                      self.media_player.stateChanged.connect(self.on_state_changed)
                                      self.media_player.play()
                                  except Exception as e:
                                      print(e)
                                  
                              def check_stream(self):
                                  if self.media_player.state() == QMediaPlayer.StoppedState:
                                      self.initialize_media_player()
                              
                              def on_state_changed(self, state):
                                  if state == QMediaPlayer.PlayingState:
                                      print("Media player Playing")
                                  else:
                                      print("Media player stopped")
                          
                          JonBJ 1 Reply Last reply
                          0
                          • V VIDYUL SHAH

                            @JonB This what I have written. I have to put a label giving the status of video sream connected or disconnected. According to current logic it labelsetText switches between connected and disconnected. Is there any other kind of logic that could be used and this problem also is solved.

                            class VideoStream(QDialog):
                                ImageUpdate = pyqtSignal(QImage)
                                
                                def __init__(self):
                                    super(VideoStream, self).__init__()
                                    loadUi('VideoStream.ui', self)
                                    self.media_url = "rtsp://127.0.0.1:5000/test"
                                    self.initialize_media_player()
                                def initialize_media_player(self):
                                    try:
                                        self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                                        self.media_player.setVideoOutput(self.video_label)
                                        media_content = QMediaContent(QUrl(self.media_url))
                                        self.media_player.setMedia(media_content)
                            
                                        self.timer = QTimer(self)
                                        self.timer.timeout.connect(self.check_stream)
                                        self.timer.start(10)  # Check stream every second
                            
                                        self.media_player.stateChanged.connect(self.on_state_changed)
                                        self.media_player.play()
                                    except Exception as e:
                                        print(e)
                                    
                                def check_stream(self):
                                    if self.media_player.state() == QMediaPlayer.StoppedState:
                                        self.initialize_media_player()
                                
                                def on_state_changed(self, state):
                                    if state == QMediaPlayer.PlayingState:
                                        print("Media player Playing")
                                    else:
                                        print("Media player stopped")
                            
                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #12

                            @VIDYUL-SHAH
                            Well, it's in the right direction. The important thing is: did it help? Do the retries end up working such that it starts working when " I connect my Ethernet cable", which is what you wanted?

                            V 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @VIDYUL-SHAH
                              Well, it's in the right direction. The important thing is: did it help? Do the retries end up working such that it starts working when " I connect my Ethernet cable", which is what you wanted?

                              V Offline
                              V Offline
                              VIDYUL SHAH
                              wrote on last edited by
                              #13

                              @JonB Yes it starts but I notice after keeping ethernet unplugged for a long time. It gives warning messages 3-4 (Warning: "Error sending UDP packets") times in an interval as specified in QTimer. Ans then it will start the recurrsion and keep checking for the connection until I again plug-in the ethernet. Is there any way to reduce this time apart from setting the qtimer and another query is that for the connection/disconnection label which i asked previously.

                              JonBJ 1 Reply Last reply
                              0
                              • V VIDYUL SHAH

                                @JonB Yes it starts but I notice after keeping ethernet unplugged for a long time. It gives warning messages 3-4 (Warning: "Error sending UDP packets") times in an interval as specified in QTimer. Ans then it will start the recurrsion and keep checking for the connection until I again plug-in the ethernet. Is there any way to reduce this time apart from setting the qtimer and another query is that for the connection/disconnection label which i asked previously.

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by JonB
                                #14

                                @VIDYUL-SHAH
                                I can't say about the UDP packets sending errors. We previously said you might increase the timer timeout (perhaps exponentially) each time it fails so as to reduce the attempts by not hammering it while it is failing/cable is unplugged. I don't know/understand if you have a query about a label, you can set a label to whatever whenever you want.

                                I have to say I think it is "unusual" to try to cater automatically for "ethernet unplugged" or similar. If Url is unavailable it's unavailable, I would expect user to retry and/or change Url. But that's up to you.

                                And just btw self.timer.start(10) # Check stream every second is not every second, it's 100 times per second. Which is "hammering" and seems way too frequent. But if you implement the "exponential timeout increase" that will also alter that, though you should be aware of the units QTimer works on.

                                Oh, and unless you find you have to do it, I wouldn't recreate a new QMediaPlayer (and a QTimer for that matter) every time. Isn't it enough to just call self.media_player.play() on each timeout?

                                V 2 Replies Last reply
                                0
                                • JonBJ JonB

                                  @VIDYUL-SHAH
                                  I can't say about the UDP packets sending errors. We previously said you might increase the timer timeout (perhaps exponentially) each time it fails so as to reduce the attempts by not hammering it while it is failing/cable is unplugged. I don't know/understand if you have a query about a label, you can set a label to whatever whenever you want.

                                  I have to say I think it is "unusual" to try to cater automatically for "ethernet unplugged" or similar. If Url is unavailable it's unavailable, I would expect user to retry and/or change Url. But that's up to you.

                                  And just btw self.timer.start(10) # Check stream every second is not every second, it's 100 times per second. Which is "hammering" and seems way too frequent. But if you implement the "exponential timeout increase" that will also alter that, though you should be aware of the units QTimer works on.

                                  Oh, and unless you find you have to do it, I wouldn't recreate a new QMediaPlayer (and a QTimer for that matter) every time. Isn't it enough to just call self.media_player.play() on each timeout?

                                  V Offline
                                  V Offline
                                  VIDYUL SHAH
                                  wrote on last edited by VIDYUL SHAH
                                  #15

                                  @JonB @SGaist I was playing with:

                                  def initialize_media_player(self):
                                          self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface)
                                          media_content = QMediaContent(QUrl(self.media_url))
                                          self.media_player.setMedia(media_content)
                                          self.media_player.setVideoOutput(self.video_label)
                                          
                                          self.check_stream()
                                  
                                          '''self.timer = QTimer(self)
                                          self.timer.timeout.connect(self.check_stream)
                                          self.timer.start(5)  # Check stream every second '''
                                  
                                          self.media_player.stateChanged.connect(self.on_state_changed)
                                          self.media_player.play()
                                  
                                  def check_stream(self):
                                          if self.media_player.mediaStatus() == QMediaPlayer.UnknownMediaStatus:
                                              print('1')
                                          if self.media_player.mediaStatus() == QMediaPlayer.NoMedia:
                                              print('2')
                                          if self.media_player.mediaStatus() == QMediaPlayer.LoadingMedia:
                                              print('3')
                                          if self.media_player.mediaStatus() == QMediaPlayer.LoadedMedia:
                                              print('4')
                                          if self.media_player.mediaStatus() == QMediaPlayer.StalledMedia:
                                              print('5')
                                          if self.media_player.mediaStatus() == QMediaPlayer.BufferingMedia:
                                              print('6')
                                          if self.media_player.mediaStatus() == QMediaPlayer.BufferedMedia:
                                              print('7')
                                          if self.media_player.mediaStatus() == QMediaPlayer.EndOfMedia:
                                              print('8')
                                          if self.media_player.mediaStatus() == QMediaPlayer.InvalidMedia:
                                              print('9')
                                  

                                  What I did was I ran my user interface (UI) on one computer without executing the Python script on another computer to stream live video. This resulted in the following output on the screen:

                                  3
                                  Error: "Could not open resource for reading and writing."

                                  Then, I simply uncommented the timer section without executing the Python script on the other computer to stream the live video. This resulted in the following output on the screen:

                                  3
                                  9
                                  9
                                  9
                                  9
                                  9
                                  ..... (continuously)

                                  Later, I ran my UI on one computer while also running the Python script on the other computer to stream live video. This resulted in the following output on the screen:

                                  3
                                  7
                                  7
                                  7
                                  7
                                  7
                                  ..... (continuously)

                                  Now what I have understood is that using a few lines from 'def check_stream(self)' I have to build a logic which will check if the data is streamed from the URL or is the streaming has stopped and then wait for a few seconds to again play the media but I am unable to build this logic and also unable to understand when and how to catch these lines from self.media_player.play().

                                  1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @VIDYUL-SHAH
                                    I can't say about the UDP packets sending errors. We previously said you might increase the timer timeout (perhaps exponentially) each time it fails so as to reduce the attempts by not hammering it while it is failing/cable is unplugged. I don't know/understand if you have a query about a label, you can set a label to whatever whenever you want.

                                    I have to say I think it is "unusual" to try to cater automatically for "ethernet unplugged" or similar. If Url is unavailable it's unavailable, I would expect user to retry and/or change Url. But that's up to you.

                                    And just btw self.timer.start(10) # Check stream every second is not every second, it's 100 times per second. Which is "hammering" and seems way too frequent. But if you implement the "exponential timeout increase" that will also alter that, though you should be aware of the units QTimer works on.

                                    Oh, and unless you find you have to do it, I wouldn't recreate a new QMediaPlayer (and a QTimer for that matter) every time. Isn't it enough to just call self.media_player.play() on each timeout?

                                    V Offline
                                    V Offline
                                    VIDYUL SHAH
                                    wrote on last edited by
                                    #16

                                    @JonB Thank you for all the inputs, I somehow managed to play and stop the video and also display error message.

                                    1 Reply Last reply
                                    0
                                    • V VIDYUL SHAH has marked this topic as solved on

                                    • Login

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