bugfix
This commit is contained in:
parent
ebc27fc306
commit
14cd252502
@ -5,13 +5,25 @@ from aiortc import VideoStreamTrack, AudioStreamTrack
|
|||||||
class MyMediaPlayer(MediaPlayer):
|
class MyMediaPlayer(MediaPlayer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MyAudioStreamTrack(AudioStreamTrack):
|
class MyTrackBasea:
|
||||||
def __init__(self, source=None):
|
def __init__(self, source=None):
|
||||||
super().__init__()
|
|
||||||
self.source = source
|
self.source = source
|
||||||
|
self.track = self.set_track()
|
||||||
|
self.track.on('ended', self.reload)
|
||||||
|
|
||||||
|
def set_track(self):
|
||||||
|
if self.kind == 'audio':
|
||||||
|
self.track = self.source.audio
|
||||||
|
else:
|
||||||
|
self.track = self.source.video
|
||||||
|
|
||||||
|
def self.reload(self):
|
||||||
|
print(f'reload the source----{self.source._file_path}')
|
||||||
|
self.set_source(MyMediaPlayer(self.source._file_path))
|
||||||
|
|
||||||
def set_source(self, source):
|
def set_source(self, source):
|
||||||
self.source = source
|
self.source = source
|
||||||
|
self.set_track()
|
||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
if self.source is None:
|
if self.source is None:
|
||||||
@ -23,20 +35,13 @@ class MyAudioStreamTrack(AudioStreamTrack):
|
|||||||
f = await self.source.audio.recv()
|
f = await self.source.audio.recv()
|
||||||
return f
|
return f
|
||||||
|
|
||||||
class MyVideoStreamTrack(VideoStreamTrack):
|
|
||||||
|
class MyAudioStreamTrack(AudioStreamTrack, MyTrackBasea):
|
||||||
def __init__(self, source=None):
|
def __init__(self, source=None):
|
||||||
super().__init__()
|
AudioStreamTrack.__init__(self)
|
||||||
self.source = source
|
MyTrackBase.__init__(self, source=source)
|
||||||
|
|
||||||
def set_source(self, source):
|
class MyVideoStreamTrack(VideoStreamTrack, MyTrackBasea):
|
||||||
self.source = source
|
def __init__(self, source=None):
|
||||||
|
VideoStreamTrack.__init__(self)
|
||||||
async def recv(self):
|
MyTrackBase.__init__(self, source=source)
|
||||||
if self.source is None:
|
|
||||||
return None
|
|
||||||
f = await self.source.video.recv()
|
|
||||||
while f is None:
|
|
||||||
print('MyVideoTrack::recv(): will reload source')
|
|
||||||
self.set_source(MyMediaPlayer(self.source._file_path))
|
|
||||||
f = await self.source.video.recv()
|
|
||||||
return f
|
|
||||||
|
Loading…
Reference in New Issue
Block a user