This commit is contained in:
yumoqing 2022-02-11 14:23:28 +08:00
parent 77d505af2d
commit 9cd8ad4099
3 changed files with 20 additions and 21 deletions

View File

@ -1,17 +1,18 @@
from ffpyplayer.player import MediaPlayer
from threading import Thread
from kivy.core.video.video_ffpyplayer import VideoFFPy
def set_headers_pattern(self, pattern, headers_str):
if not hasattr(self, 'headers_pattern'):
self.headers_pattern = {}
self.headers_pattern[pattern] = headers_str
headers_pattern = {
}
def get_spec_headers(self, filename):
if not hasattr(self, 'headers_pattern'):
return None
for p in self.headers_pattern.keys:
def set_headers_pattern(pattern, headers_str):
headers_pattern[pattern] = headers_str
def get_spec_headers(filename):
for p in headers_pattern.keys():
if p in filename:
return self.headers_pattern[p]
return headers_pattern[p]
return None
def hack_play(self):
@ -30,7 +31,7 @@ def hack_play(self):
}
if self._filename.startswith('http://') or \
self._filename.startswith('https://'):
headers = self.get_spec_headers(self._filename)
headers = get_spec_headers(self._filename)
if headers is not None:
ff_opts['headers'] = headers
print('****************')
@ -49,6 +50,4 @@ def hack_play(self):
self._thread.daemon = True
self._thread.start()
setattr(VideoFFPy, 'set_headers_pattern', set_headers_pattern)
setattr(VideoFFPy, 'get_spec_headers', get_spec_headers)
setattr(VideoFFPy, 'play', hack_play)

View File

@ -3,12 +3,12 @@ from kivy.uix.video import Video
from kivy.logger import Logger
from kivy.core.window import Window
from kivy.factory import Factory
from kivy.properties import BooleanProperty
from kivy.properties import BooleanProperty, DictProperty
from kivy.clock import Clock
from ffpyplayer.tools import set_log_callback
from hack_ffpyplayer import *
from .hack_ffpyplayer import set_headers_pattern
logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
'fatal': Logger.critical, 'error': Logger.error,
'warning': Logger.warning, 'info': Logger.info,
@ -17,6 +17,7 @@ logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
class NewVideo(Video):
center_screen = BooleanProperty(False)
h_pattern = DictProperty(None)
def __init__(self, **kw):
Video.__init__(self, **kw)
Window.allow_screensaver = False
@ -29,11 +30,11 @@ class NewVideo(Video):
self.bind(loaded=self.on_video_loaded)
self.load_status = None
Clock.schedule_interval(self.check_focus,0.2)
if self.h_pattern:
[ set_headers_pattern(k,v) for k,v in self.h_pattern.items() ]
def set_patternheaders(self, pattern, headers_str):
if not hasattr(self, '_video'):
return
self._video.set_headers_pattern(pattern, headers_str)
set_headers_pattern(pattern, headers_str)
def on_enter_focus(self, v=None):
pass

View File

@ -84,8 +84,7 @@ class WidgetCSS(object):
self.width = self.width_nm
def on_csscls(self, o, csscls):
if isinstance(self.csscls, str):
self.set_css(self.csscls)
self.set_css(self.csscls)
def set_css(self, css_str):
css = {}
@ -95,13 +94,13 @@ class WidgetCSS(object):
setattr(self,k,v)
def on_height_c(self, o, c):
if not height_c:
if not self.height_c:
return
self.size_hint_y = None
self.height = CSize(self.height_c)
def on_width_c(self, o, c):
if not width_c:
if not self.width_c:
return
self.size_hint_x = None
self.width = CSize(self.width_c)