Guest User

Untitled

a guest
Jan 14th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. from __future__ import absolute_import, division, print_function, unicode_literals
  2. __metaclass__ = type
  3.  
  4. import os
  5. os.environ['KIVY_VIDEO'] = 'ffpyplayer'
  6. # os.environ['KIVY_VIDEO'] = 'gstplayer'
  7.  
  8. from kivy.app import App
  9. from kivy.clock import Clock
  10. from kivy.uix.floatlayout import FloatLayout
  11.  
  12.  
  13. class RootWidget(FloatLayout):
  14. def __init__(self, **kwargs):
  15. super(RootWidget, self).__init__(**kwargs)
  16. Clock.schedule_once(self._bind, -1)
  17.  
  18. def _bind(self, *args):
  19. self.file_chooser.bind(selection=self.selection_changed)
  20. # Progress:
  21. self.video.bind(position=self.progress.setter('value'))
  22. self.video.bind(duration=self.progress.setter('max'))
  23. # Seek on grabbing:
  24. self.progress.bind(on_touch_down=self.down)
  25. self.progress.bind(on_touch_move=self.move)
  26. self.progress.bind(on_touch_up=self.up)
  27.  
  28. def selection_changed(self, *args):
  29. self.video.source = self.file_chooser.selection[0]
  30. self.video.state = 'play'
  31.  
  32. def down(self, _, touch):
  33. if self.progress.collide_point(*touch.pos):
  34. touch.grab(self.progress)
  35. self.video.state = 'pause'
  36.  
  37. def move(self, _, touch):
  38. if touch.grab_current == self.progress:
  39. x, y = self.progress.to_widget(*touch.pos, relative=True)
  40. percent = x / self.progress.width
  41. self.video.seek(percent)
  42.  
  43. def up(self, _, touch):
  44. if touch.grab_current == self.progress:
  45. touch.ungrab(self.progress)
  46. self.video.state = 'play'
  47.  
  48.  
  49. class TestApp(App):
  50. def build(self):
  51. return RootWidget()
  52.  
  53.  
  54. if __name__ == '__main__':
  55. TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment