Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video player #1

Open
kulothunganug opened this issue Nov 2, 2020 · 0 comments
Open

Video player #1

kulothunganug opened this issue Nov 2, 2020 · 0 comments

Comments

@kulothunganug
Copy link

kulothunganug commented Nov 2, 2020

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()
@ArtemSBulgakov ArtemSBulgakov changed the title Material Video Player need Video player Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants