This commit is contained in:
yumoqing 2021-02-28 10:23:27 +08:00
parent 18f3de6032
commit 4a9de787c7
2 changed files with 86 additions and 12 deletions

View File

@ -1,8 +1,10 @@
from kivy.properties import StringProperty
from kivy.properties import StringProperty, NumericProperty, ListProperty
from kivy.factory import Factory
from kivy.clock import Clock
from kivy.logger import Logger
from kivy.uix.image import AsyncImage
from .baseWidget import ScrollWidget, getDataHandler
from .baseWidget import ScrollWidget, getDataHandler, CSize
from .utils import CSize
import re
@ -68,7 +70,7 @@ class MarkDownParser(object):
self.text = f'{VIDEO_LEAD}'
return
title = x[0]
y = x[0].split(REFER_END,1)
y = x[1].split(REFER_END,1)
if len(y) < 2:
self.text = f'{VIDEO_LEAD}'
return
@ -89,7 +91,7 @@ class MarkDownParser(object):
self.text = f'{VIDEO_LEAD}'
return
title = x[0]
y = x[0].split(REFER_END,1)
y = x[1].split(REFER_END,1)
if len(y) < 2:
self.text = f'{VIDEO_LEAD}'
return
@ -101,8 +103,7 @@ class MarkDownParser(object):
}
}
self.result.append(d)
l = len(title) + 2 + len(url)
self.mdtext = self.mdtext[l:]
self.mdtext = y[1]
def check_key(self,t):
for k in self.mdkeys:
@ -131,6 +132,36 @@ class MarkDownParser(object):
self.text = ''
return self.result
class MDImage(AsyncImage):
parent_width=NumericProperty(None)
image_size = ListProperty(None)
def __init__(self, **kw):
super().__init__(**kw)
self.image_size = None
self.parent_width = None
self.bind(texture=self.image_loaded)
def image_loaded(self,o, *args):
self.image_size = self.texture.size
def resize(self, size):
self.parent_width = size[0]
Logger.info('MDImage: resize called, size=%s', size)
def on_image_size(self, *args):
if self.parent_width:
self.set_new_height()
def on_parent_width(self, *args):
if self.image_size:
self.set_new_height()
def set_new_height(self):
self.height = self.parent_width * self.image_size[1] \
/ self.image_size[0]
Logger.info('MDImage: set_new_height called, size=%s', self.size)
class Markdown(ScrollWidget):
"""
# Markdown
@ -167,22 +198,34 @@ description file format
self.parse_line(l)
def build_image(self,img_desc):
w = Factory.AsyncImage(soure=img_desc['url'],
keep_ratio=True,
size_hint_y=None
w = MDImage(source=img_desc['url'],
allow_stretch=True,
size_hint_y=None,
height=CSize(10),
keep_ratio=True
)
w.bind(minimum_height=w.setter('height'))
self.add_widget(w)
w.resize(self.size)
def build_video(self, video_desc):
w = Factory.NewVideo(source=video_desc['url'],
keep_ratio=True,
play=True,
play=False,
allow_stretch = True,
size_hint_y=None
)
w.height=self.width * 10 / 16
w.state = 'pause'
def f1(x):
x.state = 'play'
def f2(x):
x.state = 'stop'
w.bind(on_enter_focus=f1)
w.bind(on_leave_focus=f2)
self.add_widget(w)
w.resize(self.size)
def build_audio(self, audio_desc):
w = Factory.APlayer(source=audio_desc.url)

View File

@ -4,6 +4,7 @@ from kivy.logger import Logger
from kivy.core.window import Window
from kivy.factory import Factory
from kivy.properties import BooleanProperty
from kivy.clock import Clock
from ffpyplayer.tools import set_log_callback
@ -15,6 +16,7 @@ logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
class NewVideo(BGColorBehavior, Video):
center_screen = BooleanProperty(False)
def __init__(self,color_level=-1,radius=[],**kw):
Video.__init__(self, **kw)
BGColorBehavior.__init__(self,
@ -23,9 +25,34 @@ class NewVideo(BGColorBehavior, Video):
Window.allow_screensaver = False
set_log_callback(self.ffplayerLog)
self.register_event_type('on_open_failed')
self.register_event_type('on_leave_focus')
self.register_event_type('on_enter_focus')
self.register_event_type('on_load_success')
self.bind(source=self.record_start_time)
self.load_status = None
Clock.schedule_interval(self.check_focus,0.2)
def on_enter_focus(self, v=None):
Logger.info('NewView: enter focus')
def on_leave_focus(self, v=None):
Logger.info('NewView: leave focus')
def check_focus(self,*args):
if not self.parent:
return
w = self.parent
pos = w.to_widget(*Window.center)
if self.collide_point(*pos):
self.center_screen = True
else:
self.center_screen = False
def on_center_screen(self,o, v):
if v:
self.dispatch('on_enter_focus')
else:
self.dispatch('on_leave_focus')
def resize(self, size):
v_size = self.get_video_size()
@ -67,9 +94,13 @@ class NewVideo(BGColorBehavior, Video):
def get_video_size(self):
if hasattr(self._video,'_ffplayer'):
try:
return self._video._ffplayer.get_frame()[0][0].get_size()
except:
return None
else:
Logger.error('NewVideo: _video has not _ffplayer, do nothong')
return None
def audioswitch(self,btn=None):
if hasattr(self._video,'_ffplayer'):