Skip to content

Commit

Permalink
changed progress bar from percentage to time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaraali committed Oct 16, 2024
1 parent 90f2323 commit 88993a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class ConfigManager:
CURRENT_VERSION = "1.5.3" # Set your current version here
CURRENT_VERSION = "1.5.4" # Set your current version here

def __init__(self):
self.config = {}
Expand Down
39 changes: 31 additions & 8 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, QMetaObject, Slot
from PySide6.QtCore import QEvent, QMetaObject, QPoint, Qt, QTimer, Slot
from PySide6.QtGui import QCursor, QGuiApplication
from PySide6.QtWidgets import QFrame, QVBoxLayout, QMainWindow, QProgressBar
from PySide6.QtWidgets import QFrame, QMainWindow, QProgressBar, QVBoxLayout


class VideoPlayer(QMainWindow):
Expand Down Expand Up @@ -65,6 +65,8 @@ def __init__(self, config_manager, *args, **kwargs):
self.progress_bar.setRange(0, 1000) # Use 1000 steps for smoother updates
self.progress_bar.setValue(0)
self.progress_bar.setVisible(False)
self.progress_bar.setTextVisible(True)
self.progress_bar.setFormat("00:00 / 00:00")
self.mainFrame.layout().addWidget(self.progress_bar)

self.update_timer = QTimer(self)
Expand All @@ -85,10 +87,28 @@ def seek_video(self, event):
seek_position = click_position / width
self.media_player.set_position(seek_position)

def format_time(self, milliseconds):
seconds = int(milliseconds / 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
if hours > 0:
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
else:
return f"{minutes:02d}:{seconds:02d}"

def update_progress(self):
if self.media_player.is_playing():
position = self.media_player.get_position()
self.progress_bar.setValue(int(position * 1000))
current_time = self.media_player.get_time()
total_time = self.media.get_duration()

if total_time > 0:
formatted_current = self.format_time(current_time)
formatted_total = self.format_time(total_time)
self.progress_bar.setFormat(f"{formatted_current} / {formatted_total}")
self.progress_bar.setValue(int(current_time * 1000 / total_time))
else:
self.progress_bar.setFormat("Live")
self.progress_bar.setValue(0)

def wheelEvent(self, event):
delta = event.angleDelta().y()
Expand Down Expand Up @@ -166,7 +186,9 @@ def play_video(self, video_url):
self.media_player.set_media(self.media)

events = self.media_player.event_manager()
events.event_attach(vlc.EventType.MediaPlayerLengthChanged, self.on_media_length_changed)
events.event_attach(
vlc.EventType.MediaPlayerLengthChanged, self.on_media_length_changed
)
self.media.parse_with_options(1, 0)

self.media_player.play()
Expand Down Expand Up @@ -338,11 +360,12 @@ def on_media_length_changed(self, event):

@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.progress_bar.setFormat("00:00 / " + self.format_time(duration))
self.update_timer.start()
else: # Live content
self.progress_bar.setVisible(False)
self.update_timer.stop()
self.progress_bar.setVisible(False) # Hide the progress bar
self.progress_bar.setFormat("Live")
# self.update_timer.start()

0 comments on commit 88993a8

Please sign in to comment.