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 pass
class FILEDataHandler(EventDispatcher): class FILEDataHandler(EventDispatcher):
def __init__(self, url, subfixes=[],params={}): def __init__(self, url, suffixs=[],params={}):
self.url = url self.url = url
self.subfixes=subfixes self.subfixes=subfixes
self.params = params self.params = params
@ -101,7 +101,7 @@ class FILEDataHandler(EventDispatcher):
self.page = self.params.get('page',1) self.page = self.params.get('page',1)
if not url.startswith('file://'): if not url.startswith('file://'):
raise Exception('%s is not a file url' % url) 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)) ] rescursive=self.params.get('rescursive',False)) ]
self.total_files = len(self.files) self.total_files = len(self.files)
x = 0 if self.total_files % self.page_rows == 0 else 1 x = 0 if self.total_files % self.page_rows == 0 else 1
@ -183,3 +183,9 @@ class HTTPDataHandler(EventDispatcher):
callback=self.onSuccess, callback=self.onSuccess,
errback=self.onError) 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: try:
widget = self.__build(desc,ancestor=ancestor) widget = self.__build(desc,ancestor=ancestor)
self.dispatch('on_built',widget) self.dispatch('on_built',widget)
print('widgetBuild():&&&&&&&&&&&&&&&&&',widget)
except Exception as e: except Exception as e:
print('&&&&&&&&&&&&&&&&&',e) print_exc()
doerr(None,e) doerr(None,e)
print('&&&&&&&&&&&&&&&&&',e) print('&&&&&&&&&&&&&&&&&',e)
return return

View File

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