3

I want to stop this kivy video on tap event(play by default). I'm running this on the raspberry PI. Here's my kv and python code.

<VideoScreen>:
name: 'Video'
BoxLayout:
    Video:
        id: 'video1'
        source: './media/Sequence_#1.mp4'
        state: root.current_video_state
        volume: 1
        options: {'eos': 'loop'}
        allow_stretch: True

The video is played in loops and on tap it switches to new screen 'Login' but the video doesn't stops and is still playing in loops(I want to stop this after new screen is loaded). There are many other screen screens connected to video screen using screen manager. Assume that loading screens works fine. Ignore the indentation.

class VideoScreen(Screen):
    current_video_state = StringProperty()
    def __init__(self, **kwargs):
        super(VideoScreen,  self).__init__(**kwargs)
        self.bind(on_touch_down = self.on_stop)
        self.current_video_state = self.get_set_current_video_state()

    def get_set_current_video_state(self, *args):
        while(args):
            print('arg', args[0])
            if args[0] == 'pause':
            return 'pause'
        return 'play'

    def on_stop(self,  *args):
        self.state = 'pause'
        self.get_set_current_video_state('pause')
        self.parent.current = 'Login'
Kallz
  • 3,244
  • 1
  • 20
  • 38
vsr
  • 1,025
  • 9
  • 17
  • Does the video widget work for you on the raspberry pi? I couldn't get it to work and I think a lot of others had the same problem. And we used a workaround like https://gist.github.com/natcl/005dc4c6434ed7b5a59a that. Did you do anything specific to make it work on the raspberry pi? – PalimPalim Oct 07 '17 at 06:24

1 Answers1

2
Video:
    # ...
    state: root.current_video_state

This part binds Video widget's state to property current_video_state: each time current_video_state changed, video's state would be changed same way. You should change this variable on (touch) event to pause video:

def on_stop(self,  *args):
    self.current_video_state = 'pause'  # this will change video state to 'pause'
    self.parent.current = 'Login'
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159