This commit is contained in:
yumoqing 2022-02-11 13:20:52 +08:00
parent b07b37b22b
commit 77d505af2d
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,54 @@
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
def get_spec_headers(self, filename):
if not hasattr(self, 'headers_pattern'):
return None
for p in self.headers_pattern.keys:
if p in filename:
return self.headers_pattern[p]
return None
def hack_play(self):
if self._ffplayer and self._state == 'paused':
self._ffplayer.toggle_pause()
self._state = 'playing'
return
self.load()
self._out_fmt = 'rgba'
ff_opts = {
'paused': True,
'out_fmt': self._out_fmt,
'sn': True,
'volume': self._volume,
}
if self._filename.startswith('http://') or \
self._filename.startswith('https://'):
headers = self.get_spec_headers(self._filename)
if headers is not None:
ff_opts['headers'] = headers
print('****************')
print('*VideoFFPy():ff_opts=', ff_opts)
print('****************')
self._ffplayer = MediaPlayer(
self._filename, callback=self._player_callback,
thread_lib='SDL',
loglevel='info', ff_opts=ff_opts)
# Disabled as an attempt to fix kivy issue #6210
# self._ffplayer.set_volume(self._volume)
self._thread = Thread(target=self._next_frame_run, name='Next frame')
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

@ -8,6 +8,7 @@ from kivy.clock import Clock
from ffpyplayer.tools import set_log_callback
from hack_ffpyplayer import *
logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
'fatal': Logger.critical, 'error': Logger.error,
'warning': Logger.warning, 'info': Logger.info,
@ -29,6 +30,11 @@ class NewVideo(Video):
self.load_status = None
Clock.schedule_interval(self.check_focus,0.2)
def set_patternheaders(self, pattern, headers_str):
if not hasattr(self, '_video'):
return
self._video.set_headers_pattern(pattern, headers_str)
def on_enter_focus(self, v=None):
pass