Skip to content

Commit

Permalink
Merge pull request #15 from pcjco/pcjco_player_progress
Browse files Browse the repository at this point in the history
fix progress bar not shown
  • Loading branch information
ozankaraali authored Oct 16, 2024
2 parents 136f18d + d511e15 commit 90f2323
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions video_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys

import vlc
from PySide6.QtCore import QEvent, QPoint, Qt, QTimer
from PySide6.QtCore import QEvent, QPoint, Qt, QTimer, QMetaObject, Slot
from PySide6.QtGui import QCursor, QGuiApplication
from PySide6.QtWidgets import QFrame, QHBoxLayout, QMainWindow, QProgressBar
from PySide6.QtWidgets import QFrame, QVBoxLayout, QMainWindow, QProgressBar


class VideoPlayer(QMainWindow):
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(self, config_manager, *args, **kwargs):
self.mainFrame = QFrame()
self.setCentralWidget(self.mainFrame)
self.setWindowTitle("QiTV Player")
t_lay_parent = QHBoxLayout()
t_lay_parent = QVBoxLayout()
t_lay_parent.setContentsMargins(0, 0, 0, 0)

self.video_frame = QFrame()
Expand Down Expand Up @@ -164,19 +164,12 @@ def play_video(self, video_url):

self.media = self.instance.media_new(video_url)
self.media_player.set_media(self.media)
self.media_player.play()

# Check if the content is VOD or live
self.media.parse()
duration = self.media.get_duration()

if duration > 0: # VOD content
self.progress_bar.setVisible(True)
self.update_timer.start()
else: # Live content
self.progress_bar.setVisible(False)
self.update_timer.stop()
events = self.media_player.event_manager()
events.event_attach(vlc.EventType.MediaPlayerLengthChanged, self.on_media_length_changed)
self.media.parse_with_options(1, 0)

self.media_player.play()
self.adjust_aspect_ratio()
self.show()

Expand Down Expand Up @@ -339,3 +332,17 @@ def adjust_aspect_ratio(self):
width, height = video_size
if width > 0 and height > 0:
self.aspect_ratio = width / height

def on_media_length_changed(self, event):
QMetaObject.invokeMethod(self, "media_length_changed", Qt.QueuedConnection)

@Slot()
def media_length_changed(self):
# Check if the content is VOD or live
duration = self.media.get_duration()
if duration > 0: # VOD content
self.progress_bar.setVisible(True)
self.update_timer.start()
else: # Live content
self.progress_bar.setVisible(False)
self.update_timer.stop()

0 comments on commit 90f2323

Please sign in to comment.