def play_video(self,widget): try: self.foldername = self.ids.select_folder_label.text self.filename = self.ids.file_name.text if self.foldername is None or self.foldername == "": Toast().toast("Please select a valid folder...") if self.filename is None or self.filename == "": Toast().toast("Please select a valid filename...") self.filename = os.path.join(self.foldername, self.filename) if self.video: self.ids.videoContainer.remove_widget(self.video) self.video = None self.video = Video() self.video.source = self.filename self.video.state = 'play' #self.video.options = {'eos':'stop'} self.video.bind(eos=self.VideoDone) self.video.allow_stretch = True self.ids.videoContainer.add_widget(self.video) except Exception as e: print("Error: ", __name__, " Exception ", e) applogger().logger.error('{ModuleName} - Error = {Exception}'.format(ModuleName=__name__, Exception = e))
def on_index(self, instance, value): if self.media: if isinstance(self.media, Video): self.media.play = False self.media = None value = value % len(self.item.medias) media = self.item.medias[value] name, ext = splitext(media) ext = ext[1:].lower() # convert media url to local media path (all medias are already downloaded) from museolib.utils import no_url media = join(self.parent.parent.parent.parent.app.expo_dir, 'otherfiles', no_url(media)) if not isfile(media): print " ### Oops, this media is not downloaded !" try: if ext in ('mp3', 'ogg', 'flac', 'wav'): w = Label(text="It's a song : " + media) if not isfile(media): w = Label(text="Song not downloaded.") elif ext in ('avi', 'mkv', 'mp4', 'ogv', 'mpg', 'mpeg', 'dv'): w = Video(source=media, play=True) else: w = AsyncImage(source=media) except: w = Label(text='Unable to read that media') self.content.clear_widgets() self.content.add_widget(w) self.media = w
def build(self): # This line is for running under Windows but crashes things on the Raspberry Pi # Window.fullscreen = "auto" Window.show_cursor = False self.photo = Image() self.photo.allow_stretch = True # Without this line the Raspberry Pi starts blacking out photos after a few images. self.photo.nocache = True self.video = Video(allow_stretch=True, options={ 'eos': 'stop', 'autoplay': True }) self.video.bind(position=self.on_position_change, duration=self.on_duration_change, texture=self.on_texture_change) self.video.opacity = 0 self.video.allow_stretch = True self.video.nocache = True self.video.volume = self.VIDEO_VOLUME_ON_OR_OFF self.screen = FloatLayout() self.screen.add_widget(self.photo) self.screen.add_widget(self.video) Clock.schedule_once(self.next_photo_or_video, 1) return self.screen
def get_video(self, path=None, is_random=False, paused=False, eos="stop", player=None,volume=0): path = "Videos/" + path if is_random: files = os.listdir(path) video_path = path + "/" + random.choice(files) else: print(path) video_path = path if player is not None: player.source=video_path player.state="stop" if paused else "play" player.eos=eos player.volume=volume return player s = { "source": video_path, "state": "stop" if paused else "play", "options": {"allow_stretch": True}, "volume":volume, "size":self.screen.size, "eos":eos } player = Video(**s) player.bind(on_eos=self.on_video_end) return player
def build(self): # config = self.config video = Video(source=filename) video.state = 'play' video.options = {'eos': 'loop'} video.allow_stretch = True return video
def build(self): # Anchor Layout1 anchorLayout1 = AnchorLayout(anchor_x='left', anchor_y='bottom') button1 = Button(text='test', size_hint=(0.3, 0.3)) def callback(instance): print('The button <%s> is being pressed' % instance.text) publish.single("test", hostname="192.168.1.11") button1.bind(on_press=callback) anchorLayout1.add_widget(button1) # Anchor Layout2 anchorLayout2 = AnchorLayout() anchorLayout2.anchor_x = 'right' anchorLayout2.anchor_y = 'top' # Add the anchor layouts to a box layout vid = Video(source="http://192.168.1.11:8081/", play=True) anchorLayout2.add_widget(vid) # Create a box layout boxLayout = BoxLayout() # Add both the anchor layouts to the box layout boxLayout.add_widget(anchorLayout1) boxLayout.add_widget(anchorLayout2) # Return the boxlayout widget return boxLayout
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 play_video(self, index): print "PLAY " + str(index) self.black() if len(self.videos) <= index: return src = self.videos[index] self.video = Video(source=src) self.video.allow_stretch = True self.video.state = "play" Clock.schedule_once(self.start_video, 0.2)
def __init__(self, **kwargs): super().__init__(**kwargs) self.player = Video(source='./Video/crackers.mp4') self.player.state = 'stop' self.player.size_hint = [1, 1] self.player.allow_stretch = True self.player.allow_fullscreen = True self.add_widget(self.player) with self.canvas.before: Color(0, 0, 0) Rectangle(size=(2000, 2000), pos=self.pos)
def build(self): if len(argv) > 1: filename = argv[1] else: curdir = dirname(__file__) filename = join(curdir, 'softboy.avi') video = Video(source=filename, play=True) scatter = Scatter() video.bind(texture_size=scatter.setter('size')) scatter.add_widget(video) return scatter
def __init__(self, **kwargs): super(VideoScreen, self).__init__(**kwargs) self.video = Video(source='test.mkv', state='stop') # Specific function that switches to EscapeRoom screen def switch(self, kwargs): sm.switch_to(PasswordScreen()) # Bind a callback to eos event. Eos is when the video ends self.video.bind(eos=switch) self.add_widget(self.video)
def __init__(self, **kwargs): super().__init__(**kwargs) self.layout = FloatLayout() self.add_widget(self.layout) # background self.img = Image(source='images/luminaria.jpg', allow_stretch=True, keep_ratio=False) self.msg = Video(source='images/msg.MOV', size_hint=(None,None),size=(220,100), pos=(251, 730), options={'eos':'loop'}, play=True) self.layout.add_widget(self.img) self.layout.add_widget(self.msg)
def show_popup_preview(self, *args): player = Video(source=self.savedir + "/" + self.img_filenamedir + "/" + self.img_filenamedir + "_mux_movie.mp4", state='play', options={'allow_stretch': True}) videobox = BoxLayout() videobox.add_widget(player) self.popup_player = Popup(title='', size_hint=(.680, .460), content=videobox, auto_dismiss=True, separator_height=0) self.popup_player.open()
def setup_ui(self): layout = BoxLayout(orientation='vertical') # 请注意,由于 kivy 的官方实现 video 是有 bug 的 # 所以官方文档也是错的,你要按照我给的这样的例子来写才行,这是我看源码扒出来的可行方法 # 自动播放的写法 v = Video(source='demo.mp4', state='play') self.video = v # on_loaded 函数会在视频载入成功后被调用 v.bind(texture_size=self.on_loaded) # on_position_change 函数会在视频播放的时候不断调用,具体你播放一下就好了 v.bind(position=self.on_position_change) layout.add_widget(v) return layout
def build(self): self.box = BoxLayout(orientation='vertical') self.video = Video(source='nq.mp4') self.video.state = 'play' self.video.options = {'eos': 'loop'} self.video.allow_stretch = True self.box.add_widget(self.video) but = Button(text='Caption!', size_hint=(.4, 1)) but.bind(on_press=self.callback) self.box.add_widget(but) return self.box
def build(self): f = FloatLayout() g = GridLayout(cols=5, rows=2, row_force_default=True, row_default_height=80) layout = BoxLayout(size_hint=(1, None), height=50, spacing=100, pos_hint={'top': 1}) v = Video(source='driver.mp4', state='play', options={'eos':'loop'}) l1 = Label(text="jenkins", font_size=32) l2 = Label(text="git", font_size=32) f.add_widget(v) """ label1 = ColoredLabel(text="jenkins output", pos_hint={'top': 1, 'right': .1}, size_hint=(None, None) , background_color=(160,160,160,.5)) f.add_widget(label1) label2 = ColoredLabel(text="git output", pos_hint={'top': 1, 'right': .5}, size_hint=(None, None) , background_color=(160,160,160,.5)) f.add_widget(label2) label3 = ColoredLabel(text="dev output", pos_hint={'top': 1, 'right': .8}, size_hint=(None, None) , background_color=(160,160,160,.5)) f.add_widget(label3) """ text1 = "jenkins" text1 = "red" if text1 == "red": label1 = ColoredLabel(text=text1, background_color=(204,0,0,.5)) layout.add_widget(label1) else: label1 = ColoredLabel(text=text1, background_color=(160,160,160,.5)) layout.add_widget(label1) label2 = ColoredLabel(text="git", background_color=(160,160,160,.5)) layout.add_widget(label2) label3 = ColoredLabel(text="portal", background_color=(160,160,160,.5)) layout.add_widget(label3) label4 = ColoredLabel(text="network", background_color=(160,160,160,.5)) layout.add_widget(label4) label5 = ColoredLabel(text="skyscape", background_color=(160,160,160,.5)) layout.add_widget(label5) f.add_widget(layout) #w.add_widget(f) return f
def on_state(self, instance, value): if self._video is None: self._video = Video(source=self.source, state='play', 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.state = value
def start(self, values): with self.canvas: Color(1, 1, 1, 1) self.can = Rectangle(pos=(155, 200), size=(685, 500)) if self.layerUtama == 1: self.rec = Image(source="", pos=(155, 200), size=(685, 500)) elif self.layerUtama == 2: self.rec = Video(source="", pos=(155, 200), size=(685, 500)) if values == 1: if self.layer1 != None: self.changeBackground(self.layer1) elif values == 2: if self.layer2 != None: self.changeBackground(self.layer2)
def playVideo(self): layout = BoxLayout(orientation='vertical') video = Video(source='../video/Img/P2_1.mp4', state='play', size_hint=(1, 0.9)) layout.add_widget(video) button = Button(text='Revenir au jeu', size_hint=(1, 0.1)) layout.add_widget(button) popup = Popup(title='Ecoute bien ! ', content=layout, size_hint=(None, None), size=(600, 600), auto_dismiss=False) button.bind(on_press=popup.dismiss) popup.open()
def __init__(self, name): self.screen = Screen(name=name) self.root = BoxLayout(orientation='vertical') # self.video = Video(source='./1.mp4', state='play', options={'allow_stretch': True, 'eos':'loop'}, size_hint=(1, 1)) self.video = Video(source='./hourglass.mp4', state='play', options={'allow_stretch': True, 'eos':'loop'}, size_hint=(1, 1)) self.root.add_widget(self.video) w1 = Widget(size_hint=(.2, 1)) self.btn = Button(text='Show!', size_hint=(.4, 1)) self.btn2 = Button(text='Once more!', size_hint=(.4, 1)) r2 = BoxLayout(size_hint=(1, .1)) r2.add_widget(self.btn) r2.add_widget(w1) r2.add_widget(self.btn2) self.root.add_widget(r2) self.screen.add_widget(self.root)
def playVideo(self, chaine): """Function to display a video """ layout = BoxLayout(orientation='vertical') video = Video(source=chaine, state='play', size_hint=(1, 0.9)) layout.add_widget(video) #button = Button(text='Revenir au jeu', size_hint=(1, 0.1)) #layout.add_widget(button) popup = Popup(title='Ecoute bien ! ', content=layout, size_hint=(None, None), size=(600, 600), auto_dismiss=False) #button.bind(on_press=popup.dismiss) popup.open()
def __init__(self, source, fNames_url): self.fNames_url = fNames_url relative_layout = RelativeLayout() self.popup = Popup(title=source, size_hint=(0.9, 0.95), content=relative_layout, auto_dismiss=False) self.gif = Video(source=source, volume=0, state='play', anim_loop=0, \ allow_stretch=True, size_hint=(1,0.9), pos_hint={'y':0.09}) self.close_btn = Button(text='close [x]', size_hint=(None,None), size=(70,20), \ pos_hint={'x':0.003,'y':0.003}, background_normal='img/alpha.png') self.close_btn.bind(on_release=self.close_btn_press) self.mute_btn = Button(text='mute [x]', size_hint=(None,None), size=(70,20), \ pos_hint={'x':0.004,'y':0.04}, background_normal='img/alpha.png') self.mute_btn.bind(on_release=self.mute_btn_press) self.prev_btn = Button(text='[<-] previous', size_hint=(None,None), pos_hint={'x':0.2, 'y':0.003}, \ size=(100,28), background_normal='img/alpha.png') self.prev_btn.bind(on_release=self.prev_btn_press) self.next_btn = Button(text='next [->]', size_hint=(None,None), pos_hint={'x':0.88 , 'y':0.003}, \ size=(70, 28), background_normal='img/alpha.png') self.next_btn.bind(on_release=self.next_btn_press) self.play_pause_btn = Button(size_hint=(None,None), pos_hint={'center_x':0.57, 'y':0.03}, \ size=(57,30), background_normal='img/alpha.png') self.play_pause_btn.bind(on_release=self.play_pause_btn_press) self.play_pause_img = Image(source='img/pause.png', size=(35, 35)) self.play_pause_label = Label(text='playing', size_hint=(None,None), size=(70,20), \ pos_hint={'center_x':0.57,'center_y':0.017}) self.dot_dot_label = Label(text='',size_hint=(None,None), size=(20,20), \ pos_hint={'x':0.599, 'center_y':0.017}) self.play_pause_btn.add_widget(self.play_pause_img) self.label_updating = Clock.schedule_interval(self.update_label, 0.5) for i in [self.gif, self.close_btn, self.mute_btn, self.prev_btn, self.dot_dot_label, \ self.next_btn, self.play_pause_btn, self.play_pause_label]: relative_layout.add_widget(i) Clock.schedule_once(self.update_properties, 0) self.popup.open()
def __init__(self, **kwargs): super(ScreenThree, self).__init__(**kwargs) self.video1 = Video(source=os.path.join(original_dir, "cityCC0.mpg")) float_layout = FloatLayout() self.label1 = Label(text="Just a place holder video", opacity=0, pos_hint={ "x": 0, "bottom": 1 }, size_hint=[0.2, 0.1]) # self.label2 = Label(text="loading video", opacity=0) # pos_hint = {"x": 0, "bottom": 1}, size_hint=[0.2, 0.1] self.add_widget(float_layout) float_layout.add_widget(self.label1, index=0) # float_layout.add_widget(self.label2) float_layout.add_widget(self.video1, index=1) self.video1.opacity = 0
def build(self): Window.bind(on_keyboard=self.on_keyboard) # bind our handler self._list_channels = self._wink_client.get_list_channels() ch_url, err = self._wink_client.get_channel_url( str(self._list_channels[self._current_ch] ['nc_channel_id'])) #self._wink_client._fairplay_cert_url) #url_key_1 = 'https://s40757.cdn.ngenix.net/certificates/8BA6D7AC942DE15E1B375DEF7FA20918757A6533' #self._wink_client.load_cert_ott(url_key_1) self.video = Video(source=ch_url) self.video.state = 'play' self.video.options = {'eos': 'loop'} self.video.allow_stretch = True #self.video.pos_hint = {'top': 1.0} self._grid_1 = GridLayout(cols=2, row_force_default=True, row_default_height=40) self._grid_menu = GridLayout(cols=8) self._grid_channels = GridLayout(cols=3) self.video.add_widget(self._grid_1) self.l = Label(text='Hello world', font_size='20sp', size_hint=(1, 0.17)) #self.l.pos( print(self.l.pos) self.img1 = AsyncImage(source=self._wink_tv.__IMAGES_URL__ + '/sdp/nc-snapshot1569398092010.jpg', pos_hint={ 'x': 0.0, 'y': 0.8 }) self.video.add_widget(self._grid_menu) self.video.add_widget(self.img1) self.video.add_widget(self.l) self._grid_1.add_widget(self._grid_channels) self.l_ch = [] for i in range(5): lab1 = Label(text=self._list_channels[i]['name'], font_size='20sp') self._grid_channels.add_widget(lab1) self.l_ch += [lab1] print(Window.size) return self.video
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 kivy import kivy_examples_dir from os.path import join, dirname, abspath source = abspath(join(kivy_examples_dir, "widgets", "cityCC0.mpg")) 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)
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)
def __init__(self, **kwargs): super(Video_s, self).__init__(**kwargs) layout = RelativeLayout() endbutton = Button(text='HANG UP', size_hint=(.2, .1), pos_hint={ 'x': 0.1, 'y': 0.05 }) endbutton.bind(on_press=lambda x: self.hangup()) layout.add_widget(endbutton) chatbutton = Button(text='SEND', size_hint=(.2, .1), pos_hint={ 'x': 0.75, 'y': 0.05 }) chatbutton.bind(on_press=lambda x: self.sendmsg()) layout.add_widget(chatbutton) self.msg_send = TextInput(hint_text="Enter your message", size_hint=(0.3, .35), pos_hint={ 'x': 0.67, 'y': 0.17 }) self.msg_recv = TextInput(hint_text="Waiting for messages...", size_hint=(0.3, .35), pos_hint={ 'x': 0.67, 'y': 0.52 }) self.video = Video(source='test.h264', size_hint=(.6, .8), pos_hint={ 'x': 0.05, 'y': 0.1 }) layout.add_widget(self.video) layout.add_widget(self.msg_recv) layout.add_widget(self.msg_send) self.add_widget(layout)
def on_index(self, instance, value): if self.media: if isinstance(self.media, Video): self.media.play = False self.media = None value = value % len(self.item.medias) media = self.item.medias[value] name, ext = splitext(media) ext = ext[1:].lower() try: if ext in ('avi', 'mkv', 'mp4', 'ogv', 'mpg', 'mpeg', 'dv'): w = Video(source=media, play=True) else: w = AsyncImage(source=media) except: w = Label(text='Unable to read that media') self.content.clear_widgets() self.content.add_widget(w) self.media = w
def __init__(self, **kwargs): super(InfoScreen, self).__init__(**kwargs) self.fixed_layer = Widget(size_hint=(None, None), size=(0, 0)) self.add_widget(self.fixed_layer) self.video = Video(text="video", pos=(0, 700), size=(1080, 920)) self.video.volume = 1.0 self.fixed_layer.add_widget(self.video) self.title_label = Label(text="TITLE", text_size=(1080, None), font_size=80, bold=True, pos=(0, 410), halign='center', width=1080) self.fixed_layer.add_widget(self.title_label) self.movie = self.app.get_random_movie() #self.size = (1080,1921) self.size = (1080, 1920) Clock.schedule_interval(self.video_eos_check, 2.0)
def __init__(self, **kwargs): # 父类构造方法 super().__init__(**kwargs) # 进度位置变化 def on_position_change(instance, value): # 打印文本 print('进度位置变化', value) # 持续时间变化 def on_duration_change(instance, value): # 打印文本 print('持续时间变化', value) # 视频 video = Video(source='34.mp4', state='play') # 视频信号与槽 video.bind(position=on_position_change, duration=on_duration_change) # 加组件(视频) self.add_widget(video)