diff --git a/kivyblocks/ffpyplayer_video.py b/kivyblocks/ffpyplayer_video.py index ac034aa..d1c1f91 100644 --- a/kivyblocks/ffpyplayer_video.py +++ b/kivyblocks/ffpyplayer_video.py @@ -9,7 +9,8 @@ from kivy.factory import Factory from kivy.app import App from kivy.core.window import Window from kivy.uix.image import Image -from kivy.uix.widget import Widget +from kivy.uix.label import Label +from kivy.uix.boxlayout import BoxLayout from kivy.clock import Clock from kivy.properties import StringProperty, BooleanProperty, \ OptionProperty, NumericProperty @@ -33,14 +34,22 @@ vhks = ['v_src', 'repeat' ] -class FFVideo(WidgetReady, VideoBehavior, Widget): +class FFVideo(WidgetReady, VideoBehavior, BoxLayout): def __init__(self, **kw): kw1 = {k:v for k,v in kw.items() if k in vhks} kw1['renderto'] = 'background' kw2 = {k:v for k,v in kw.items() if k not in vhks} - Widget.__init__(self, **kw2) + kw2['orientation'] = 'vertical' + BoxLayout.__init__(self, **kw2) VideoBehavior.__init__(self, **kw1) WidgetReady.__init__(self) + self.msg_w = Label(text='Hello') + self.add_widget(self.msg_w) + self.bind(on_frame=self.show_info) + + def show_info(self, o, d): + txt = f"size={d['size']}, vpos={d['pos']}, vsize={d['texture_size']}" + self.msg_w.text = txt """ class FFVideo(WidgetReady, Image): diff --git a/kivyblocks/version.py b/kivyblocks/version.py index 68eb9b6..ab45471 100644 --- a/kivyblocks/version.py +++ b/kivyblocks/version.py @@ -1 +1 @@ -__version__ = '0.4.5' +__version__ = '0.4.6' diff --git a/kivyblocks/videobehavior.py b/kivyblocks/videobehavior.py index 993d4e2..2951a2a 100644 --- a/kivyblocks/videobehavior.py +++ b/kivyblocks/videobehavior.py @@ -145,13 +145,6 @@ class VideoBehavior(object): def on_frame(self, *args): return - w = self.get_root_window() - if w is None: - self.status = 'stop' - print('root is None................') - - if self._player is None: - return def __del__(self): self._play_stop() @@ -301,7 +294,7 @@ class VideoBehavior(object): size=self.size, colorfmt='rgb') buf = b'\x00' * int(self.width * self.height * 3) image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte') - self.texture = image_texture + self._draw_texture(image_texture, *self.size) self.is_black = True def show_yuv420(self, img): @@ -346,14 +339,23 @@ class VideoBehavior(object): # print('img_size=', w, h, 'window size=', self.size) def draw_texture(self, texture, w, h): - if self.width != w and self.height != h: - self.set_video_size() - return + d = self._draw_texture(texture, w, h) + if d: + self.dispatch('on_frame', d) + + def _draw_texture(self, texture, w, h): + if abs(self.width - w) > 1 and abs(self.height - h) > 1: + self._set_video_size() + if w > self.width: + w = self.width + if h > self.height: + h = self.height canvas = self.canvas if self.renderto == 'background': canvas = self.canvas.before elif self.renderto == 'cover': canvas = self.canvas.after + p = 0 if self.duration > 0: p = self.position / self.duration * self.width pos = (self.width - w)/2, (self.height - h)/2 @@ -364,6 +366,15 @@ class VideoBehavior(object): Line(points=[0, 1, self.width, 1], width=2) Color(1,0,0,1) Line(points=[0,1,p,1], width=2) + d = { + 'texture':texture, + 'position':self.position, + 'duration':self.duration, + 'pos':pos, + 'texture_size':(w, h), + 'size':self.size + } + return d def video_handle(self, *args): if self._update_task: @@ -420,7 +431,6 @@ class VideoBehavior(object): self.show_yuv420(img) else: self.show_others(img) - self.dispatch('on_frame', self.last_frame) self.last_frame = None self.vh_task = Clock.schedule_once(self.video_handle, 0) self.block_task = Clock.schedule_once(self.video_blocked, self.timeout)