kivyblocks/kivyblocks/hack_ffpyplayer.py

57 lines
1.4 KiB
Python
Raw Normal View History

2022-02-11 13:20:52 +08:00
2022-02-11 14:23:28 +08:00
from ffpyplayer.player import MediaPlayer
from threading import Thread
2022-02-11 13:20:52 +08:00
from kivy.core.video.video_ffpyplayer import VideoFFPy
2022-02-11 14:23:28 +08:00
headers_pattern = {
}
2022-02-11 13:20:52 +08:00
2022-02-11 14:23:28 +08:00
def set_headers_pattern(pattern, headers_str):
headers_pattern[pattern] = headers_str
def get_spec_headers(filename):
for p in headers_pattern.keys():
2022-02-11 13:20:52 +08:00
if p in filename:
2022-02-11 14:23:28 +08:00
return headers_pattern[p]
2022-02-11 13:20:52 +08:00
return None
def hack_play(self):
2022-02-11 15:56:00 +08:00
print('****************')
print('****************')
print('hack_play() called ...')
2022-02-11 13:20:52 +08:00
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://'):
2022-02-11 14:23:28 +08:00
headers = get_spec_headers(self._filename)
2022-02-11 13:20:52 +08:00
if headers is not None:
2022-02-14 13:31:22 +08:00
ff_opts['headers'] = "$'%s'" % headers
2022-02-11 13:20:52 +08:00
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()
2022-03-07 13:46:05 +08:00
# setattr(VideoFFPy, 'play', hack_play)