This commit is contained in:
yumoqing 2020-08-26 07:15:17 +08:00
parent deee578398
commit 32d0c64822
2 changed files with 74 additions and 78 deletions

View File

@ -1,45 +1,30 @@
from kivy.uix.video import Video from kivy.uix.video import Video
from kivy.logger import Logger from kivy.logger import Logger
from kivy.core.window import Window from kivy.core.window import Window
from kivy.utils import platform
from kivy.factory import Factory from kivy.factory import Factory
from kivy.properties import BooleanProperty from kivy.properties import BooleanProperty
from ffpyplayer.tools import set_log_callback from ffpyplayer.tools import set_log_callback
desktopOSs=[
"win",
"linux",
"macosx"
]
logger_func = {'quiet': Logger.critical, 'panic': Logger.critical, logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
'fatal': Logger.critical, 'error': Logger.error, 'fatal': Logger.critical, 'error': Logger.error,
'warning': Logger.warning, 'info': Logger.info, 'warning': Logger.warning, 'info': Logger.info,
'verbose': Logger.debug, 'debug': Logger.debug} 'verbose': Logger.debug, 'debug': Logger.debug}
othersplatforms=['ios','android']
class NewVideo(Video): class NewVideo(Video):
fullscreen = BooleanProperty(False)
_fullscreen_state = False
def __init__(self,**kw): def __init__(self,**kw):
super(NewVideo, self).__init__(**kw) super(NewVideo, self).__init__(**kw)
Window.allow_screensaver = False
set_log_callback(self.ffplayerLog) set_log_callback(self.ffplayerLog)
if hasattr(self._video, '_ffplayer'): if hasattr(self._video, '_ffplayer'):
self.ffplayer = self._video._ffplayer self.ffplayer = self._video._ffplayer
Window.bind(size=self.ctrl_fullscreen) def on_state(self,*args):
if self.state == 'play':
def ctrl_fullscreen(self,*args): Window.allow_screensaver = False
print('NewVideo(),crtl_fullscreen',args)
if Window.width > Window.height:
self.fullscreen = True
else: else:
self.fullscreen = False Window.allow_screensaver = True
def ffplayerLog(self, msg, level): def ffplayerLog(self, msg, level):
msg = msg.strip() msg = msg.strip()
if msg: if msg:
@ -48,61 +33,3 @@ class NewVideo(Video):
def audioswitch(self,btn=None): def audioswitch(self,btn=None):
x = self._video._ffplayer.request_channel('audio') x = self._video._ffplayer.request_channel('audio')
def on_fullscreen(self, instance, value):
print('NewVideo::on_fullscreen(),value=', value)
window = self.get_parent_window()
if not window:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'window not found.')
if value:
self.fullscreen = False
return
if not self.parent:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'no parent.')
if value:
self.fullscreen = False
return
if value:
Window.fullscreen = True
self._fullscreen_state = state = {
'parent': self.parent,
'pos': self.pos,
'size': self.size,
'pos_hint': self.pos_hint,
'size_hint': self.size_hint,
'window_children': window.children[:]}
if platform in desktopOSs:
Window.maximize()
# remove all window children
for child in window.children[:]:
window.remove_widget(child)
# put the video in fullscreen
if state['parent'] is not window:
state['parent'].remove_widget(self)
window.add_widget(self)
# ensure the video widget is in 0, 0, and the size will be
# readjusted
self.pos = (0, 0)
self.pos_hint = {}
self.size_hint = (1, 1)
else:
if platform in desktopOSs:
Window.restore()
Window.fullscreen = False
state = self._fullscreen_state
window.remove_widget(self)
for child in state['window_children']:
window.add_widget(child)
self.pos_hint = state['pos_hint']
self.size_hint = state['size_hint']
self.pos = state['pos']
self.size = state['size']
if state['parent'] is not window:
state['parent'].add_widget(self)
Factory.register('NewVideo',NewVideo)

View File

@ -1,6 +1,18 @@
from kivy.event import EventDispatcher from kivy.event import EventDispatcher
from kivy.core.window import Window
from kivy.utils import platform
from kivy.properties import BooleanProperty
desktopOSs=[
"win",
"linux",
"macosx"
]
class WidgetReady(EventDispatcher): class WidgetReady(EventDispatcher):
fullscreen = BooleanProperty(False)
_fullscreen_state = False
def __init__(self): def __init__(self):
self.register_event_type('on_ready') self.register_event_type('on_ready')
self._ready = False self._ready = False
@ -17,3 +29,60 @@ class WidgetReady(EventDispatcher):
def reready(self): def reready(self):
self._ready = False self._ready = False
self.ready() self.ready()
def on_fullscreen(self, instance, value):
print('NewVideo::on_fullscreen(),value=', value)
window = self.get_parent_window()
if not window:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'window not found.')
if value:
self.fullscreen = False
return
if not self.parent:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'no parent.')
if value:
self.fullscreen = False
return
if value:
Window.fullscreen = True
self._fullscreen_state = state = {
'parent': self.parent,
'pos': self.pos,
'size': self.size,
'pos_hint': self.pos_hint,
'size_hint': self.size_hint,
'window_children': window.children[:]}
if platform in desktopOSs:
Window.maximize()
# remove all window children
for child in window.children[:]:
window.remove_widget(child)
# put the video in fullscreen
if state['parent'] is not window:
state['parent'].remove_widget(self)
window.add_widget(self)
# ensure the video widget is in 0, 0, and the size will be
# readjusted
self.pos = (0, 0)
self.pos_hint = {}
self.size_hint = (1, 1)
else:
Window.fullscreen = False
if platform in desktopOSs:
Window.restore()
state = self._fullscreen_state
window.remove_widget(self)
for child in state['window_children']:
window.add_widget(child)
self.pos_hint = state['pos_hint']
self.size_hint = state['size_hint']
self.pos = state['pos']
self.size = state['size']
if state['parent'] is not window:
state['parent'].add_widget(self)