@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().