Skip to content

Commit

Permalink
fullscreen fix attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaraali committed May 25, 2024
1 parent 2ddb2ee commit b7245a1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions video_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import vlc
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtWidgets import QMainWindow, QVBoxLayout, QWidget
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget


class VideoPlayer(QMainWindow):
Expand Down Expand Up @@ -50,11 +50,13 @@ def toggle_fullscreen(self):
if self.fullscreen:
self.showNormal()
self.setWindowFlags(self.windowFlags() & ~Qt.FramelessWindowHint)
self.show()
self.fullscreen = False
else:
self.showFullScreen()
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
self.show()
self.fullscreen = True
self.show()
self._re_attach_video()

def closeEvent(self, event):
self.save_window_settings()
Expand All @@ -72,16 +74,9 @@ def create_video_area(self):
self.layout.addWidget(self.videoframe)

def play_video(self, video_url):
if platform.system() == "Linux":
self.media_player.set_xwindow(self.videoframe.winId())
elif platform.system() == "Windows":
self.media_player.set_hwnd(self.videoframe.winId())
elif platform.system() == "Darwin":
self.media_player.set_nsobject(int(self.videoframe.winId()))

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

def stop_video(self):
self.media_player.stop()
Expand Down Expand Up @@ -145,12 +140,21 @@ def apply_window_settings(self):
video_player_pos.get("height", 800),
)

def _re_attach_video(self):
if self.media:
if platform.system() == "Linux":
self.media_player.set_xwindow(self.videoframe.winId())
elif platform.system() == "Windows":
self.media_player.set_hwnd(self.videoframe.winId())
elif platform.system() == "Darwin":
self.media_player.set_nsobject(int(self.videoframe.winId()))
self.media_player.play()


class VideoFrame(QWidget):
def __init__(self, parent=None):
super(VideoFrame, self).__init__(parent)
self.player = parent # Store the VideoPlayer instance

def mouseDoubleClickEvent(self, event):
self.player.fullscreen = not self.player.fullscreen
self.player.toggle_fullscreen() # Call the method on VideoPlayer instance
self.player.toggle_fullscreen() # Call the method on VideoPlayer instance

0 comments on commit b7245a1

Please sign in to comment.