This commit is contained in:
yumoqing 2020-05-07 18:12:15 +08:00
parent 2da40112bb
commit e699b60d94
3 changed files with 30 additions and 35 deletions

View File

@ -93,7 +93,7 @@ class PressableLabel(ButtonBehavior, Text):
pass
class FILEDataHandler(EventDispatcher):
def __init__(self, url, subfixes=[],params={}):
def __init__(self, url, suffixs=[],params={}):
self.url = url
self.subfixes=subfixes
self.params = params
@ -101,7 +101,7 @@ class FILEDataHandler(EventDispatcher):
self.page = self.params.get('page',1)
if not url.startswith('file://'):
raise Exception('%s is not a file url' % url)
self.files = [i for i in listFile(url[7:],suffixs=subfixes, \
self.files = [i for i in listFile(url[7:],suffixs=suffixs, \
rescursive=self.params.get('rescursive',False)) ]
self.total_files = len(self.files)
x = 0 if self.total_files % self.page_rows == 0 else 1
@ -183,3 +183,9 @@ class HTTPDataHandler(EventDispatcher):
callback=self.onSuccess,
errback=self.onError)
def getDataHandler(url,**kwargs):
if url.startswith('file://'):
return FILEDataHandler(url,**kwargs)
return HTTPDataHandler(url, **kwaegs)

View File

@ -430,9 +430,8 @@ class Blocks(EventDispatcher):
try:
widget = self.__build(desc,ancestor=ancestor)
self.dispatch('on_built',widget)
print('widgetBuild():&&&&&&&&&&&&&&&&&',widget)
except Exception as e:
print('&&&&&&&&&&&&&&&&&',e)
print_exc()
doerr(None,e)
print('&&&&&&&&&&&&&&&&&',e)
return

View File

@ -47,23 +47,27 @@ class BaseVPlayer(FloatLayout, SwipeBehavior):
self.register_event_type('on_next')
self.register_event_type('on_previous')
Window.allow_screensaver = False
self._video = Video(allow_stretch=True,pos_hint={'x': 0, 'y': 0},size_hint=(1,1))
self._video = Video(allow_stretch=True)
self.add_widget(self._video)
self.nextdir = None
if type(vfile) == type([]):
self.playlist = vfile
else:
self.playlist = [vfile]
self.curplay = 0
self.old_volume = 0
self._video.bind(eos=self.on_eos)
self._video.bind(state=self.on_state)
self._video.bind(position=self.positionChanged)
self.bind(on_swipe_down=self.previous)
self.bind( on_swipe_up=self.next)
self.bind(on_swipe_up=self.next)
set_log_callback(self.ffplayerLog)
self.play()
if hasattr(self._video._video, '_ffplayer'):
self.ffplayer = self._video._video._ffplayer
def positionChanged(self,o,v):
pass
def setSource(self,s):
self.stop()
self.curplay = 0
@ -85,6 +89,7 @@ class BaseVPlayer(FloatLayout, SwipeBehavior):
def on_previous(self, o=None, v=None):
pass
def ffplayerLog(self, msg, level):
msg = msg.strip()
if msg:
@ -96,15 +101,16 @@ class BaseVPlayer(FloatLayout, SwipeBehavior):
if self.curplay >= 0:
self._video.source = self.playlist[self.curplay]
self._video.state = 'play'
def on_eos(self,o=None,v=None):
self.next()
else:
Logger.info('VPlaer: self.curpay < 0')
def next(self,o=None,v=None):
self.nextdir = 'down'
self.stop()
self.dispatch('on_next',self)
def previous(self,o=None,v=None):
self.nextdir = 'up'
self.stop()
self.dispatch('on_previous',self)
@ -113,6 +119,10 @@ class BaseVPlayer(FloatLayout, SwipeBehavior):
Window.allow_screensaver = False
else:
Window.allow_screensaver = True
if self._video.state == 'stop':
if self.nextdir is None:
self.dispatch('on_next',self)
self.nextdir = None
def on_fullscreen(self, instance, value):
window = self.get_parent_window()
@ -196,8 +206,7 @@ class BaseVPlayer(FloatLayout, SwipeBehavior):
self._video.volume = self.old_volume
def stop(self):
self._video.state = 'pause'
# self._video.state = 'stop'
self._video.unload()
def pause(self,t=None):
if self._video.state == 'play':
@ -239,7 +248,6 @@ class VPlayer(BaseVPlayer):
self._popup = None
self.menu_status = False
self.manualMode = False
self.update_task = None
self.pb = None
if vfile:
if type(vfile) == type([]):
@ -296,6 +304,9 @@ class VPlayer(BaseVPlayer):
self._video.seek(self.slider.value/self._video.duration)
self.manualMode = False
def positionChanged(self,o,v):
self.update_slider(None)
def update_slider(self,t):
if self._video.state != 'play':
return
@ -310,18 +321,6 @@ class VPlayer(BaseVPlayer):
self.slider.max = self._video.duration
self.maxposition.text = self.totime(self._video.duration)
def on_eos(self,o=None,v=None):
if self.update_task is not None:
self.update_task.cancel()
self.update_tasl = None
super().on_eos()
def stop(self):
if self.update_task is not None:
self.update_task.cancel()
self.update_task = None
super().stop()
def __del__(self):
self.stop()
@ -424,15 +423,6 @@ class VPlayer(BaseVPlayer):
else:
self.btn_pause.source = blockImage('pause.png')
def on_state(self,o,v):
BaseVPlayer.on_state(self,o,v)
if self._video.state == 'play':
self.update_task = Clock.schedule_interval(self.update_slider,1)
else:
if self.update_task:
self.update_task.cancel()
self.update_task = None
if __name__ == '__main__':
class MyApp(App):
def build(self):