Skip to content

Instantly share code, notes, and snippets.

@nbonfire
Last active August 29, 2015 14:12
Show Gist options
  • Save nbonfire/657365a4ef51db5db425 to your computer and use it in GitHub Desktop.
Save nbonfire/657365a4ef51db5db425 to your computer and use it in GitHub Desktop.
How can I get the video to hide itself when it's done? Right now the on_stop callback never gets called
videos= glob(join(dirname('.'), '*.mp4'))
keys=['a','s','d','f','g','h','j','k','l']
videodict=dict(zip(keys,videos))
class VideoLayout(FloatLayout):
def __init__(self, **kwargs):
super(VideoLayout, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down=self.keypress)
self.video_list=[
{
'name':video,
'video':
Video(source=video,
state='stop',
id='playingvideo',
pos=(0,0),
allow_stretch=True,
size_hint=(1,1)
)
} for video in videos]
for v in self.video_list:
print v['video'].events()
v['video'].bind(on_stop=self.stop_if_done())
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down=self.keypress)
self._keyboard = None
def stop_if_done(self, *args):
if isinstance(self.children[0],Video):
self.remove_widget(self.children[0])
def keypress(self, keyboard, keycode, text, modifiers):
#keycode[1] is the key
print keycode[1]
global videodict
#self.video_box.source = videos[video_num]
print videodict[keycode[1]]
video = next((v['video'] for v in self.video_list if v['name']==videodict[keycode[1]]),None)
if video:
print video
print self.children
if isinstance(self.children[0],Video):
try:
self.children[0].state='stop'
self.remove_widget(self.children[0])
except AttributeError:
pass
video.seek(0)
video.state='play'
self.add_widget(video,index=0)
self.current_video=video
return True
class TestApp(App):
def build(self):
global videos
root = VideoLayout()
#root.add_widget(self.background_img)
#root.add_widget(Video())
#root.add_widget(Rectangle(source='0-0.png'))
return root
@nbonfire
Copy link
Author

looks like it's bugged in 1.8 with gstreamer and on_eos and on_state dont trigger. Instead use position and duration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment