本文整理汇总了Python中kivy.uix.video.Video.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Video.bind方法的具体用法?Python Video.bind怎么用?Python Video.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.video.Video
的用法示例。
在下文中一共展示了Video.bind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_video_unload
# 需要导入模块: from kivy.uix.video import Video [as 别名]
# 或者: from kivy.uix.video.Video import bind [as 别名]
def test_video_unload(self):
# fix issue https://github.com/kivy/kivy/issues/2275
# AttributeError: 'NoneType' object has no attribute 'texture'
from kivy.uix.video import Video
from kivy.clock import Clock
from kivy.base import runTouchApp, stopTouchApp
from os.path import join, dirname
here = dirname(__file__)
source = join(here, "..", "..", "examples", "widgets", "softboy.avi")
video = Video(source=source, play=True)
Clock.schedule_once(lambda x: stopTouchApp(), 1)
def unload_video(video, position):
if position > 0.01:
video.unload()
Clock.schedule_once(lambda x: stopTouchApp(), 0.1)
video.bind(position=unload_video)
runTouchApp(video)
示例2: VideoPlayer
# 需要导入模块: from kivy.uix.video import Video [as 别名]
# 或者: from kivy.uix.video.Video import bind [as 别名]
#.........这里部分代码省略.........
if not thumbnail:
filename = self.source.rsplit('.', 1)
thumbnail = filename[0] + '.png'
self._image = VideoPlayerPreview(source=thumbnail, video=self)
self.container.add_widget(self._image)
def _load_annotations(self):
if not self.container:
return
self._annotations_labels = []
annotations = self.annotations
if not annotations:
filename = self.source.rsplit('.', 1)
annotations = filename[0] + '.jsa'
if exists(annotations):
with open(annotations, 'r') as fd:
self._annotations = load(fd)
if self._annotations:
for ann in self._annotations:
self._annotations_labels.append(
VideoPlayerAnnotation(annotation=ann))
def on_state(self, instance, value):
if self._video is not None:
self._video.state = value
def _set_state(self, instance, value):
self.state = value
def _do_video_load(self, *largs):
self._video = Video(source=self.source, state=self.state,
volume=self.volume, pos_hint={'x': 0, 'y': 0},
**self.options)
self._video.bind(texture=self._play_started,
duration=self.setter('duration'),
position=self.setter('position'),
volume=self.setter('volume'),
state=self._set_state)
def on_play(self, instance, value):
value = 'play' if value else 'stop'
return self.on_state(instance, value)
def on_volume(self, instance, value):
if not self._video:
return
self._video.volume = value
def on_position(self, instance, value):
labels = self._annotations_labels
if not labels:
return
for label in labels:
start = label.start
duration = label.duration
if start > value or (start + duration) < value:
if label.parent:
label.parent.remove_widget(label)
elif label.parent is None:
self.container.add_widget(label)
def seek(self, percent):
'''Change the position to a percentage of the duration. Percentage must
be a value between 0-1.
.. warning::
示例3: Karaotool
# 需要导入模块: from kivy.uix.video import Video [as 别名]
# 或者: from kivy.uix.video.Video import bind [as 别名]
class Karaotool(FloatLayout):
def __init__(self, **kwargs):
super(Karaotool, self).__init__(**kwargs)
self.source = kwargs.get('source', None)
if self.source == None:
self.selecttextfile = Popup(title='Select the lirycs')
self.selecttextfile.content = BoxLayout(orientation='vertical')
self.selecttextfile.content.add_widget(Button(text='Seleccionar archivo') )
self.selecttextfile.content.add_widget(Button(text='Insertar texto') )
self.selecttextfile.open()
else:
self.base_filename = os.path.splitext(self.source)[0]
with open(self.base_filename + '.kot') as f: #open karaotool text file
self.content = f.readlines()
self.line = 0;
self.video = Video(source=self.source, state='play', allow_stretch=True, keep_ratio=False)
self.video.bind(on_loaded=self.on_loaded)
self.kar_english = LabelShadow(text='KARAOKELAND',
size_hint_y=None,
color=(0,0,0,1),
font_size=32 )
self.add_widget(self.video)
self.add_widget(self.kar_english)
#si existe el archivo con los tiempos
if os.path.exists(self.base_filename + '.kos'):
self.kar_spanish = LabelShadow(text='KARAOKELAND ESP',
size_hint_y=1,
color=(0,0,0,1),
font_size=32 )
self.add_widget(self.kar_spanish)
self.fsteps = open(self.base_filename + '.kos') #steps
self.steps = self.fsteps.readlines()
try:
self.efsteps = open(self.base_filename + '.koe') #subtitulos en lenguaje traducido
self.esteps = self.efsteps.readlines()
except:
pass
#Clock.schedule_interval(self.stepchecker, .1)
self.video.bind(position=self.on_position)
self.cursteptime = self.steps[self.line]
else:
self.btn_stepline = Button(text='Iniciar !',
#size_hint=(1,None),
on_press=self.nextline
)
self.add_widget(self.btn_stepline, index=len(self.children) )
#open for steps creation
self.fsteps = open(self.base_filename + '.kos', 'w+') #karaotool steps
def on_loaded(self, w):
print("Iniciando video")
def on_position(self, w, val):
if val > float(self.cursteptime):
try:
if hasattr(self, "old_kar_english"):
self.remove_widget(self.old_kar_english)
self.old_kar_english = self.kar_english
#subir titulo
Animation(y=self.old_kar_english.y+50, opacity=.5, duration=.5).start(self.old_kar_english)
#self.kar_english.y += 80
self.kar_english = LabelShadow(text=self.content[self.line],
size_hint_y=None,
color=(0,0,0,1),
font_size=32 )
#.........这里部分代码省略.........