From 77d505af2d0283c7b930af1b30fca40913c6c2aa Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 11 Feb 2022 13:20:52 +0800 Subject: [PATCH] bugfix --- kivyblocks/hack_ffpyplayer.py | 54 +++++++++++++++++++++++++++++++++++ kivyblocks/newvideo.py | 6 ++++ 2 files changed, 60 insertions(+) create mode 100644 kivyblocks/hack_ffpyplayer.py diff --git a/kivyblocks/hack_ffpyplayer.py b/kivyblocks/hack_ffpyplayer.py new file mode 100644 index 0000000..13365a4 --- /dev/null +++ b/kivyblocks/hack_ffpyplayer.py @@ -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) diff --git a/kivyblocks/newvideo.py b/kivyblocks/newvideo.py index 9fe47a3..03bc9b0 100644 --- a/kivyblocks/newvideo.py +++ b/kivyblocks/newvideo.py @@ -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