本文整理汇总了Python中kivy.uix.video.Video类的典型用法代码示例。如果您正苦于以下问题:Python Video类的具体用法?Python Video怎么用?Python Video使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Video类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_video_unload
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: _do_video_load
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)
示例3: on_play
def on_play(self, instance, value):
if self._video is None:
self._video = Video(source=self.source, play=True,
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'))
self._video.play = value
示例4: _do_video_load
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"),
)
示例5: VideoPlayer
class VideoPlayer(GridLayout):
'''VideoPlayer class. See module documentation for more information.
'''
source = StringProperty('')
'''Source of the video to read.
:attr:`source` is a :class:`~kivy.properties.StringProperty` and
defaults to ''.
.. versionchanged:: 1.4.0
'''
thumbnail = StringProperty('')
'''Thumbnail of the video to show. If None, VideoPlayer will try to find
the thumbnail from the :attr:`source` + '.png'.
:attr:`thumbnail` a :class:`~kivy.properties.StringProperty` and defaults
to ''.
.. versionchanged:: 1.4.0
'''
duration = NumericProperty(-1)
'''Duration of the video. The duration defaults to -1 and is set to the
real duration when the video is loaded.
:attr:`duration` is a :class:`~kivy.properties.NumericProperty` and
defaults to -1.
'''
position = NumericProperty(0)
'''Position of the video between 0 and :attr:`duration`. The position
defaults to -1 and is set to the real position when the video is loaded.
:attr:`position` is a :class:`~kivy.properties.NumericProperty` and
defaults to -1.
'''
volume = NumericProperty(1.0)
'''Volume of the video in the range 0-1. 1 means full volume and 0 means
mute.
:attr:`volume` is a :class:`~kivy.properties.NumericProperty` and defaults
to 1.
'''
state = OptionProperty('stop', options=('play', 'pause', 'stop'))
'''String, indicates whether to play, pause, or stop the video::
# start playing the video at creation
video = VideoPlayer(source='movie.mkv', state='play')
# create the video, and start later
video = VideoPlayer(source='movie.mkv')
# and later
video.state = 'play'
:attr:`state` is an :class:`~kivy.properties.OptionProperty` and defaults
to 'play'.
'''
play = BooleanProperty(False)
'''
.. deprecated:: 1.4.0
Use :attr:`state` instead.
Boolean, indicates whether the video is playing or not. You can start/stop
the video by setting this property::
# start playing the video at creation
video = VideoPlayer(source='movie.mkv', play=True)
# create the video, and start later
video = VideoPlayer(source='movie.mkv')
# and later
video.play = True
:attr:`play` is a :class:`~kivy.properties.BooleanProperty` and defaults
to False.
'''
image_overlay_play = StringProperty(
'atlas://data/images/defaulttheme/player-play-overlay')
'''Image filename used to show a "play" overlay when the video has not yet
started.
:attr:`image_overlay_play` is a
:class:`~kivy.properties.StringProperty` and
defaults to 'atlas://data/images/defaulttheme/player-play-overlay'.
'''
image_loading = StringProperty('data/images/image-loading.gif')
'''Image filename used when the video is loading.
:attr:`image_loading` is a :class:`~kivy.properties.StringProperty` and
defaults to 'data/images/image-loading.gif'.
'''
#.........这里部分代码省略.........
示例6: __init__
def __init__(self, *args, **kwargs):
super(MediaAction, self).__init__(*args, **kwargs)
self.media = self.meteor.find_one('media', selector={'_id': self.action.get('media')})
self.duration = self.media.get('duration')
if self.duration: self.duration = float(self.duration)
else: self.duration = 0
self.settings = self.combine_settings(self.settings, self.client.minion.get('settings'), self.media.get('settings'), self.action.get('settings'))
self.fade_length = float(self.settings.get('media_fade'))
self.max_volume = min(float(self.settings.get('media_volume')), 1.0)
self.minion_volume = min(float(self.settings.get('mediaminion_volume')), 1.0)
# TODO autodetect HTTP/HTTPS, other protocols?
mediaurl = self.meteor.find_one('settings', selector={'key': 'mediaurl'})['value']
self.sourceurl = 'http://{}{}'.format(self.client.server, urllib.parse.quote(mediaurl + self.media['location']))
self.video = None
self.audio = None
self.image = None
self.to_sync = None
if self.media['type'] == 'video':
options = {}
if self.settings.get('media_loop') == 'yes':
options['eos'] = 'loop'
self.video = Video(source = self.sourceurl, options = options)
self.to_sync = self.video
self.video.allow_stretch = True
if self.settings.get('media_preserve_aspect') == 'no':
self.video.keep_ratio = False
self.video.opacity = 0
self.video.volume = 0
self.video.state = 'play' # Convince video to preload itself - TODO find better way
elif self.media['type'] == 'audio':
self.audio = SoundLoader.load(self.sourceurl)
self.to_sync = self.audio
if self.settings.get('media_loop') == 'yes':
self.audio.loop = True
self.audio.volume = 0
elif self.media['type'] == 'image':
self.image = AsyncImage(source = self.sourceurl)
self.image.allow_stretch = True
if self.settings.get('media_preserve_aspect') == 'no':
self.image.keep_ratio = False
self.image.opacity = 0
示例7: MediaAction
class MediaAction(Action):
def __init__(self, *args, **kwargs):
super(MediaAction, self).__init__(*args, **kwargs)
self.media = self.meteor.find_one('media', selector={'_id': self.action.get('media')})
self.duration = self.media.get('duration')
if self.duration: self.duration = float(self.duration)
else: self.duration = 0
self.settings = self.combine_settings(self.settings, self.client.minion.get('settings'), self.media.get('settings'), self.action.get('settings'))
self.fade_length = float(self.settings.get('media_fade'))
self.max_volume = min(float(self.settings.get('media_volume')), 1.0)
self.minion_volume = min(float(self.settings.get('mediaminion_volume')), 1.0)
# TODO autodetect HTTP/HTTPS, other protocols?
mediaurl = self.meteor.find_one('settings', selector={'key': 'mediaurl'})['value']
self.sourceurl = 'http://{}{}'.format(self.client.server, urllib.parse.quote(mediaurl + self.media['location']))
self.video = None
self.audio = None
self.image = None
self.to_sync = None
if self.media['type'] == 'video':
options = {}
if self.settings.get('media_loop') == 'yes':
options['eos'] = 'loop'
self.video = Video(source = self.sourceurl, options = options)
self.to_sync = self.video
self.video.allow_stretch = True
if self.settings.get('media_preserve_aspect') == 'no':
self.video.keep_ratio = False
self.video.opacity = 0
self.video.volume = 0
self.video.state = 'play' # Convince video to preload itself - TODO find better way
elif self.media['type'] == 'audio':
self.audio = SoundLoader.load(self.sourceurl)
self.to_sync = self.audio
if self.settings.get('media_loop') == 'yes':
self.audio.loop = True
self.audio.volume = 0
elif self.media['type'] == 'image':
self.image = AsyncImage(source = self.sourceurl)
self.image.allow_stretch = True
if self.settings.get('media_preserve_aspect') == 'no':
self.image.keep_ratio = False
self.image.opacity = 0
def get_current_widget_index(self):
if self.shown:
if self.video:
return self.client.source.children.index(self.video)
elif self.image:
return self.client.source.children.index(self.image)
return None
def get_media_time(self):
diff = self.client.time.now() - float(self.action['time'])
if diff > 0 and self.settings.get('media_loop') == 'yes':
diff = diff % self.duration
if diff > self.duration: diff = self.duration
return diff
def get_seek_percent(self, time):
if time == 0: return 0
else: return 1 / (self.media['duration'] / time)
def media_sync(self, dt = None):
if self.shown and not self.media['type'] == 'image':
if self.video: pos = self.video.position
elif self.audio: pos = self.audio.get_pos()
if self.to_sync and abs(self.get_media_time() - pos) > media_sync_tolerance:
if self.settings.get('media_loop') == 'no' and pos > self.duration:
if self.video: self.to_sync.state = 'stop'
elif self.audio: self.audio.stop()
else:
self.to_sync.seek(self.get_seek_percent(self.get_media_time()))
# Automatic sync disabled until Kivy playback rate change is implemented
#.........这里部分代码省略.........
示例8: __init__
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
示例9: Karaotool
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 )
#.........这里部分代码省略.........