Ejemplo n.º 1
0
 def build(self):
     # config = self.config
     video = Video(source=filename)
     video.state = 'play'
     video.options = {'eos': 'loop'}
     video.allow_stretch = True
     return video
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
class VideoApp(App):
    def build(self):
        self.v = Video(source=sys.argv[1], state='play')
        self.v.bind(state=self.update_state)
        return self.v

    def update_state(self, *args):
        if self.v.state == 'stop':
            outlet.push_sample([2], time.time())
            exit()
Ejemplo n.º 7
0
class ScreenThree(Screen):
    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 video1_play(self, *dt):
        do_nothing(dt)
        self.video1.state = "play"
        # self.event1 = Clock.schedule_interval(partial(print, self.video1.loaded), 0.5)
        self.label1.opacity = 1
        self.video1.opacity = 1
        # self.label2.opacity = 0
        self.video1.volume = 1

    def on_video1_eos(self, *dt):
        do_nothing(dt, self)
        global audio_playback
        # print(self.video1.loaded)
        # Clock.schedule_once(self.video1_play)
        audio_playback = False
        change_screen_to('screen_two')
        # self.event1.cancel()

    def on_enter(self):
        self.video1.allow_stretch = True
        self.video1.state = "play"
        self.label1.opacity = 1
        self.video1.bind(eos=self.on_video1_eos)
        # self.label2.opacity = 1
        Clock.schedule_once(self._adjust_opacity, 1)
        # self.event1 = Clock.schedule_interval(self._check_loaded, 0.5)

    # def _check_loaded(self, *dt):
    #     if self.video1.loaded:
    #         self.video1.play = True
    #     do_nothing(dt, self.video1.loaded)

    def _adjust_opacity(self, *dt):
        do_nothing(dt)
        self.video1.opacity = 1
Ejemplo n.º 8
0
class VideoApp(App):
    def build(self):
        self.v = Video(source=sys.argv[1], state='play')
        self.v.bind(state=self.replay)
        return self.v

    def replay(self, *args):
        if self.v.state == 'stop':
            self.v.state = 'stop'
            time.sleep(1)
            exit()
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
class EndVideoScreen(Screen):
    def __init__(self, **kwargs):
        super(EndVideoScreen, 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(WinScreen())

        # Bind a callback to eos event. Eos is when the video ends
        self.video.bind(eos=switch)
        self.add_widget(self.video)

    # When the screen enters view, play the video
    def on_enter(self, *args):
        self.video.state = 'play'
Ejemplo n.º 14
0
    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
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 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"),
     )
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
 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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
0
 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()
Ejemplo n.º 28
0
 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)
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
    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
Ejemplo n.º 31
0
    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)
Ejemplo n.º 32
0
 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()
Ejemplo n.º 33
0
 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()
Ejemplo n.º 34
0
    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)
Ejemplo n.º 35
0
    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()
Ejemplo n.º 36
0
 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
Ejemplo n.º 37
0
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
            #Clock.schedule_once(self.media_sync, media_sync_interval)
        
    def out_animation_end(self):
        self.shown = False
        
        if self.video:
            self.video.state = 'pause'
            self.client.remove_widget(self.video)
            self.video.unload()

        elif self.audio:
            self.audio.stop()
            self.audio.unload()

        elif self.image:
            self.client.remove_widget(self.image)
        
    def check_ready(self):
        if self.get_media_time() >= 0:
            if self.video and self.video.loaded:
                return True

            elif self.audio:
                return True
                
            elif self.image and self.image._coreimage.loaded:
                return True
        
    def on_show(self, fade_length):
        self.media_sync()

        if self.video:
            self.video.state = 'play'
            self.client.add_layer_widget(self.video, self.layer)
            self.add_anim_widget(self.video, 'opacity', 1, 0)
            self.add_anim_widget(self.video, 'volume', self.max_volume * self.minion_volume, 0)
            
        elif self.audio:
            self.audio.play()
            self.add_anim_widget(self.audio, 'volume', self.max_volume * self.minion_volume, 0)
            
        elif self.image:
            self.client.add_layer_widget(self.image, self.layer)
            self.add_anim_widget(self.image, 'opacity', 1, 0)
              
        self.do_in_animation(fade_length)
        
    def on_hide(self, fade_length):
        self.do_out_animation(fade_length)
Ejemplo n.º 38
0
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'.
    '''

    image_play = StringProperty(
        'atlas://data/images/defaulttheme/media-playback-start')
    '''Image filename used for the "Play" button.

    :attr:`image_play` is a :class:`~kivy.properties.StringProperty` and
    defaults to 'atlas://data/images/defaulttheme/media-playback-start'.
    '''

    image_stop = StringProperty(
        'atlas://data/images/defaulttheme/media-playback-stop')
    '''Image filename used for the "Stop" button.

    :attr:`image_stop` is a :class:`~kivy.properties.StringProperty` and
    defaults to 'atlas://data/images/defaulttheme/media-playback-stop'.
    '''

    image_pause = StringProperty(
        'atlas://data/images/defaulttheme/media-playback-pause')
    '''Image filename used for the "Pause" button.

    :attr:`image_pause` is a :class:`~kivy.properties.StringProperty` and
    defaults to 'atlas://data/images/defaulttheme/media-playback-pause'.
    '''

    image_volumehigh = StringProperty(
        'atlas://data/images/defaulttheme/audio-volume-high')
    '''Image filename used for the volume icon when the volume is high.

    :attr:`image_volumehigh` is a :class:`~kivy.properties.StringProperty` and
    defaults to 'atlas://data/images/defaulttheme/audio-volume-high'.
    '''

    image_volumemedium = StringProperty(
        'atlas://data/images/defaulttheme/audio-volume-medium')
    '''Image filename used for the volume icon when the volume is medium.

    :attr:`image_volumemedium` is a :class:`~kivy.properties.StringProperty`
    and defaults to 'atlas://data/images/defaulttheme/audio-volume-medium'.
    '''

    image_volumelow = StringProperty(
        'atlas://data/images/defaulttheme/audio-volume-low')
    '''Image filename used for the volume icon when the volume is low.

    :attr:`image_volumelow` is a :class:`~kivy.properties.StringProperty`
    and defaults to 'atlas://data/images/defaulttheme/audio-volume-low'.
    '''

    image_volumemuted = StringProperty(
        'atlas://data/images/defaulttheme/audio-volume-muted')
    '''Image filename used for the volume icon when the volume is muted.

    :attr:`image_volumemuted` is a :class:`~kivy.properties.StringProperty`
    and defaults to 'atlas://data/images/defaulttheme/audio-volume-muted'.
    '''

    annotations = StringProperty('')
    '''If set, it will be used for reading annotations box.

    :attr:`annotations` is a :class:`~kivy.properties.StringProperty`
    and defaults to ''.
    '''

    fullscreen = BooleanProperty(False)
    '''Switch to fullscreen view. This should be used with care. When
    activated, the widget will remove itself from its parent, remove all
    children from the window and will add itself to it. When fullscreen is
    unset, all the previous children are restored and the widget is restored to
    its previous parent.

    .. warning::

        The re-add operation doesn't care about the index position of it's
        children within the parent.

    :attr:`fullscreen` is a :class:`~kivy.properties.BooleanProperty`
    and defaults to False.
    '''

    allow_fullscreen = BooleanProperty(True)
    '''By default, you can double-tap on the video to make it fullscreen. Set
    this property to False to prevent this behavior.

    :attr:`allow_fullscreen` is a :class:`~kivy.properties.BooleanProperty`
    defaults to True.
    '''

    options = DictProperty({})
    '''Optional parameters can be passed to a :class:`~kivy.uix.video.Video`
    instance with this property.

    :attr:`options` a :class:`~kivy.properties.DictProperty` and
    defaults to {}.
    '''

    # internals
    container = ObjectProperty(None)

    def __init__(self, **kwargs):
        self._video = None
        self._image = None
        self._annotations = ''
        self._annotations_labels = []
        super(VideoPlayer, self).__init__(**kwargs)
        self._load_thumbnail()
        self._load_annotations()

        if self.source:
            self._trigger_video_load()

    def _trigger_video_load(self, *largs):
        Clock.unschedule(self._do_video_load)
        Clock.schedule_once(self._do_video_load, -1)

    def on_source(self, instance, value):
        # we got a value, try to see if we have an image for it
        self._load_thumbnail()
        self._load_annotations()
        if self._video is not None:
            self._video.unload()
            self._video = None

    def _load_thumbnail(self):
        if not self.container:
            return
        self.container.clear_widgets()
        # get the source, remove extension, and use png
        thumbnail = self.thumbnail
        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::

            Calling seek() before video is loaded has no effect.
        '''
        if not self._video:
            return
        self._video.seek(percent)

    def _play_started(self, instance, value):
        self.container.clear_widgets()
        self.container.add_widget(self._video)

    def on_touch_down(self, touch):
        if not self.collide_point(*touch.pos):
            return False
        if touch.is_double_tap and self.allow_fullscreen:
            self.fullscreen = not self.fullscreen
            return True
        return super(VideoPlayer, self).on_touch_down(touch)

    def on_fullscreen(self, instance, value):
        window = self.get_parent_window()
        if not window:
            Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
                           'window not found.')
            if value:
                self.fullscreen = False
            return
        if not self.parent:
            Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
                           'no parent.')
            if value:
                self.fullscreen = False
            return

        if value:
            self._fullscreen_state = state = {
                'parent': self.parent,
                'pos': self.pos,
                'size': self.size,
                'pos_hint': self.pos_hint,
                'size_hint': self.size_hint,
                'window_children': window.children[:]}

            # remove all window children
            for child in window.children[:]:
                window.remove_widget(child)

            # put the video in fullscreen
            if state['parent'] is not window:
                state['parent'].remove_widget(self)
            window.add_widget(self)

            # ensure the video widget is in 0, 0, and the size will be
            # reajusted
            self.pos = (0, 0)
            self.size = (100, 100)
            self.pos_hint = {}
            self.size_hint = (1, 1)
        else:
            state = self._fullscreen_state
            window.remove_widget(self)
            for child in state['window_children']:
                window.add_widget(child)
            self.pos_hint = state['pos_hint']
            self.size_hint = state['size_hint']
            self.pos = state['pos']
            self.size = state['size']
            if state['parent'] is not window:
                state['parent'].add_widget(self)
Ejemplo n.º 39
0
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 )
                
                self.add_widget(self.kar_english)
                
                try:
                    self.kar_spanish.text = self.esteps[self.line]
                except:
                    pass

                
                
                self.line += 1
                
                #print "Step: ", self.video.position
                
                self.cursteptime = self.steps[self.line]
            except:
                self.kar_english.text = "END"
                self.kar_spanish.text = "FIN"
                
        
    def nextline(self, w):
        try:
            #advance one line
            self.kar_english.text = self.content[self.line]
            self.line += 1
            
            #self.kar_english.pos.y += 200
            
            self.fsteps.write(str(self.video.position) + '\n')
        except:
            self.kar_english.text = "FIN"
Ejemplo n.º 40
0
    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