2

I'm just starting out with Kivy, so please point out if I'm doing something wrong.. I'm trying to work with the video player. Namely, I can't seem to get it to recognize any "options", and I'd really like a way to hide the controls (to prevent the user from stopping/pausing/changing volume/interacting etc.. while the movie is running).

Here's what I've got so far:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.videoplayer import VideoPlayer

class MyApp(App):
    def build(self):
        self.player = VideoPlayer(fullscreen=True, allow_fullscreen=True, source='mymovie.mp4', state='play', options={'allow_stretch': True, 'eos': 'loop', 'fullscreen': True})
        return(self.player)


if __name__ == '__main__':
    MyApp().run()

eos: 'loop' above, seems to be completely ignored. As does 'fullscreen'. Double clicking the player doesn't cause it to run in full screen.

I'm testing on Windows (but hoping to port to android), and in the "console" window in the background I have 2 warnings that should help me, but I guess I don't know enough to know how to take care of it:

[WARNING           ] [VideoPlayer ] Cannot switch to fullscreen, window not found.
[WARNING           ] [VideoPlayer ] Cannot switch to fullscreen, window not found.

Ideally, I would get it running in fullscreen and would be able to disable the controls (so the user can interact with things using keyboard/touch/timer events/etc.) but I can't find any documentation on how to disable them. Any pointers?

I've managed to get the window itself to run in fullscreen, but that's not the same thing, I don't think. Thanks!

Cyclonus
  • 507
  • 5
  • 13
  • I'm not sure if I was just blind or what, but it seems like the option to loop the video ('eos':'loop') is working now. Still having trouble switching to fullscreen and hiding the video controls though : – Cyclonus Apr 27 '15 at 08:32

2 Answers2

5

I solved my issues by using kivy.uix.video.Video instead of kivy.uix.videoplayer.VideoPlayer. I don't know if that's what I was expected to do in the first place (just starting out!), but just in case someone else has this problem, here's what worked for me:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.video import Video

class MyApp(App):
    def build(self):
        video = Video(source='mymovie.mp4')
        video.state='play'
        video.options = {'eos': 'loop'}
        video.allow_stretch=True
        return video

if __name__ == '__main__':
    MyApp().run()
Cyclonus
  • 507
  • 5
  • 13
  • Did it solved you with the fullscreen. As I didn't see any fullscreen option in Video module. Is there a way where we can get the full screen option in Video? – Sunil Kumar Nerella Feb 16 '22 at 07:36
1

Here is an example I made for myself which demonstrates many of these features. It answers your question.

import kivy
kivy.require('1.9.0')
import time
import os
import sys
import psutil
import logging

from kivy.app import App
from kivy.uix.video import Video
from kivy.config import Config
from kivy.core.window import Window
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'left', 0)
Config.set('graphics', 'top',  500)
Config.set('graphics', 'resizable', 'False')
#Config.set('graphics', 'borderless',  1)
Config.set('graphics', 'width', 1127)
Config.set('graphics', 'height', 636)

class MyApp(App):

    video = None
    def build(self):
        Window.bind(on_keyboard=self.on_keyboard)  # bind our handler
        self.video = Video(source='C:\\drop.mp4')
        self.video.state='play'
        #self.video.options = {'eos': 'loop'}
        self.video.allow_stretch=True
        self.video.pos_hint = {'top': 1.0}
        self.video.bind(eos=self.VideoDone)
        return self.video

    def VideoDone(self, value, value2):
        print ("video done", value, value2)

    def on_stop(self):
        # The Kivy event loop is about to stop, set a stop signal;
        # otherwise the app window will close, but the Python process will
        # keep running until all secondary threads exit.
        print ('stopping and closing kivy')
        #self.video.state='stop'


    def on_keyboard(self, window, key, scancode, codepoint, modifier):
        print (window, key, scancode, codepoint, modifier)
        if codepoint == 'p':
            print ('pausing with p pressed')
            self.video.state='stop'
        if codepoint == 's':
            print ('starting with s pressed')
            self.video.state='play'
        if codepoint == 'r':
            print ('re-starting with r pressed')
            self.video.seek(0, precise=True)




if __name__ == '__main__':
    print ("hi")
    MyApp().run()
Tim Rausch
  • 21
  • 1