Browse Source

[voice] add on_complete callback to DCADOpusEncoderPlayable

pull/46/head
Andrei 8 years ago
parent
commit
78ac2c4338
  1. 3
      disco/voice/playable.py

3
disco/voice/playable.py

@ -227,6 +227,7 @@ class DCADOpusEncoderPlayable(BasePlayable, AbstractOpus, OpusEncoder):
def __init__(self, source, *args, **kwargs): def __init__(self, source, *args, **kwargs):
self.source = source self.source = source
self.command = kwargs.pop('command', 'dcad') self.command = kwargs.pop('command', 'dcad')
self.on_complete = kwargs.pop('on_complete', None)
super(DCADOpusEncoderPlayable, self).__init__(*args, **kwargs) super(DCADOpusEncoderPlayable, self).__init__(*args, **kwargs)
self._done = False self._done = False
@ -270,6 +271,7 @@ class DCADOpusEncoderPlayable(BasePlayable, AbstractOpus, OpusEncoder):
header = self.proc.stdout.read(OPUS_HEADER_SIZE) header = self.proc.stdout.read(OPUS_HEADER_SIZE)
if len(header) < OPUS_HEADER_SIZE: if len(header) < OPUS_HEADER_SIZE:
self._done = True self._done = True
self.on_complete()
return return
size = struct.unpack('<h', header)[0] size = struct.unpack('<h', header)[0]
@ -277,6 +279,7 @@ class DCADOpusEncoderPlayable(BasePlayable, AbstractOpus, OpusEncoder):
data = self.proc.stdout.read(size) data = self.proc.stdout.read(size)
if len(data) < size: if len(data) < size:
self._done = True self._done = True
self.on_complete()
return return
return data return data

Loading…
Cancel
Save