Get video source from filechooser in kivy

13 views
Skip to first unread message

NDD Mais

unread,
Jul 25, 2021, 8:00:06 AM7/25/21
to Kivy development

Good afternoon I'm new to Kivy, however, I want to make a file read in the videoplayer by choosing in filechooser, in any directory, however, as soon as I do (as below), it doesn't load the video file, it gives the error: expected bytes, but nonetype found. The py.code below:
import kivy

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

import os

from kivy.uix.videoplayer import VideoPlayer

Builder.load_string("""
<MyWidget>:
id: my_widget
Button
text: "open"
on_release: my_widget.open(filechooser.path, filechooser.selection)
FileChooserListView:
id: filechooser
on_selection: my_widget.selected(filechooser.selection)
""")

class MyWidget(BoxLayout):

def selected(self, filename):
print ("see: %s" % filename[0])

def open(self, path, filename):
with open(os.path.join(path, filename[0])) as filename:
print(filename.read())
videotape = VideoPlayer(source=r'{}'.format(filename))
videotape.state = "play"
videotape.options = {"eos": "loop"}
videotape.allow_stretch = True
return videotape


class MyApp(App):
def build(self):
return MyWidget()

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

Can someone help me please.
Many thanks


Reply all
Reply to author
Forward
0 new messages