Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import absolute_import, division, print_function, unicode_literals
- __metaclass__ = type
- import os
- os.environ['KIVY_VIDEO'] = 'ffpyplayer'
- # os.environ['KIVY_VIDEO'] = 'gstplayer'
- from kivy.app import App
- from kivy.clock import Clock
- from kivy.uix.floatlayout import FloatLayout
- class RootWidget(FloatLayout):
- def __init__(self, **kwargs):
- super(RootWidget, self).__init__(**kwargs)
- Clock.schedule_once(self._bind, -1)
- def _bind(self, *args):
- self.file_chooser.bind(selection=self.selection_changed)
- # Progress:
- self.video.bind(position=self.progress.setter('value'))
- self.video.bind(duration=self.progress.setter('max'))
- # Seek on grabbing:
- self.progress.bind(on_touch_down=self.down)
- self.progress.bind(on_touch_move=self.move)
- self.progress.bind(on_touch_up=self.up)
- def selection_changed(self, *args):
- self.video.source = self.file_chooser.selection[0]
- self.video.state = 'play'
- def down(self, _, touch):
- if self.progress.collide_point(*touch.pos):
- touch.grab(self.progress)
- self.video.state = 'pause'
- def move(self, _, touch):
- if touch.grab_current == self.progress:
- x, y = self.progress.to_widget(*touch.pos, relative=True)
- percent = x / self.progress.width
- self.video.seek(percent)
- def up(self, _, touch):
- if touch.grab_current == self.progress:
- touch.ungrab(self.progress)
- self.video.state = 'play'
- class TestApp(App):
- def build(self):
- return RootWidget()
- if __name__ == '__main__':
- TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment