KivyMD_Extensions
KivyMD_Extensions copied to clipboard
Video player
Description of the extension
Need for a Material Video Player extension.
Example
An example that I tried to create:
from kivy.lang import Builder
from kivy.properties import NumericProperty, OptionProperty, StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivymd.app import MDApp
Builder.load_string("""
<MDVideoPlayer>:
MDBoxLayout:
orientation: 'vertical'
Video:
id: video
source: root.source
state: root.state
on_state: root.on_play(self)
MDBoxLayout:
adaptive_height: True
orientation: 'vertical'
MDSlider:
id: slider
min: 0
max: video.duration
value: str(root.slider_value)
value: video.position if not self.active else 1
on_active: root.on_slide(video, slider)
MDBoxLayout:
adaptive_height: True
MDIconButton:
icon: root.icon
on_press:
root.play_pause()
MDIconButton:
icon: 'stop'
on_press:
root.stop(slider)
MDLabel:
text: str(round(video.position)) + '/' + str(video.duration)
size_hint: (None, None)
size: self.texture_size
font_style: 'Caption'
""")
class MDVideoPlayer(FloatLayout):
source = StringProperty()
state = OptionProperty("stop", options=("play", "pause", "stop"))
icon = StringProperty("play")
slider_value = NumericProperty(0)
def play_pause(self):
if self.icon == "play" and (self.state == "stop" or "pause"):
self.state = "play"
self.icon = "pause"
elif self.icon == "pause" and self.state == "play":
self.state = "pause"
self.icon = "play"
def stop(self, slider):
self.state = "stop"
self.slider_value = 0
self.icon = "play"
def on_play(self, vd):
vd.position = self.slider_value
def on_slide(self, slider):
print(slider, video)
video.state = "pause"
video.position = slider.value
video.state = "play"
class App(MDApp):
def build(self):
return MDVideoPlayer(source='/root/Videos/signup.mp4')
App().run()