def __init__(self, filename, **kwargs): '''Provides a basic Video Widget with options on controlling the playback. This widget is based on the Video provider. * Double tap: Pause/Play * Two Finger Double tap: Rewind :Parameters: `autostart` : bool, default to False Autostart the video at instance ''' kwargs.setdefault('autostart', False) self._touches = {} super(MTSimpleVideo, self).__init__(**kwargs) # load video self.player = Video(filename=filename) # autostart the video ? if kwargs.get('autostart'): self.player.play()
class MTSimpleVideo(MTWidget): def __init__(self, filename, **kwargs): '''Provides a basic Video Widget with options on controlling the playback. This widget is based on the Video provider. * Double tap: Pause/Play * Two Finger Double tap: Rewind :Parameters: `autostart` : bool, default to False Autostart the video at instance ''' kwargs.setdefault('autostart', False) self._touches = {} super(MTSimpleVideo, self).__init__(**kwargs) # load video self.player = Video(filename=filename) # autostart the video ? if kwargs.get('autostart'): self.player.play() def on_touch_down(self, touch): if self.collide_point(touch.x, touch.y): self._touches[touch.uid] = (touch.x, touch.y) if len(self._touches) == 2: if touch.is_double_tap: self.player.seek(0) elif touch.is_double_tap: if self.player.state == 'playing': self.player.stop() else: self.player.play() return super(MTSimpleVideo, self).on_touch_down(touch) def on_touch_up(self, touch): if touch.uid in self._touches: del self._touches[touch.uid] return super(MTSimpleVideo, self).on_touch_up(touch) def on_update(self): self.size = self.player.size self.player.update() super(MTSimpleVideo, self).on_update() def draw(self): self.player.draw() super(MTSimpleVideo, self).draw()