Last active
November 18, 2019 01:26
-
-
Save me2beats/e38a9ce043a17b84be0cd3346c69f777 to your computer and use it in GitHub Desktop.
kivy VideoPlayer toggle show/hide control panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.properties import BooleanProperty, ObjectProperty | |
from kivy.uix.videoplayer import VideoPlayer | |
#from kivy.core.window import Window | |
#Window.fullscreen = 'auto' | |
KV = """ | |
MyVideoPlayer | |
#fullscreen: True | |
source:'Sample.mp4' | |
state:'play' | |
show_controls: False | |
on_touch_down: if self.collide_point(*args[1].pos): self.show_controls = not self.show_controls | |
""" | |
class MyVideoPlayer(VideoPlayer): | |
show_controls = BooleanProperty(True) | |
controls_widget = ObjectProperty(None, allownone = True) | |
def __init__(self, **kw): | |
super().__init__(**kw) | |
self.bind(parent = self.get_controls) | |
def get_controls(self, inst, controls, *_): | |
if len(self.children): | |
self.controls_widget = self.children[0] | |
self.unbind(parent = self.get_controls) | |
def on_controls_widget(self, inst, controls): | |
self.add_or_remove_controls(self.show_controls) | |
def add_or_remove_controls(self, is_show): | |
controls = self.controls_widget | |
if not controls: return | |
if not is_show and controls in self.children: | |
self.remove_widget(controls) | |
elif is_show and not controls in self.children: | |
self.add_widget(controls) | |
def on_show_controls(self, inst, is_show): | |
self.add_or_remove_controls(is_show) | |
class MyApp(App): | |
def build(self): | |
return Builder.load_string(KV) | |
MyApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a bit ugly solution