Update torchlight_changes_unloze/torchlight3/Torchlight/FFmpegAudioPlayer.py
This commit is contained in:
parent
ff3dff14a6
commit
6715d2a07c
@ -60,6 +60,9 @@ class FFmpegAudioPlayer():
|
||||
|
||||
def PlayURI(self, uri, position, rubberband = None, dec_params = None, bitrate = None,
|
||||
backwards = None, *args):
|
||||
if self.Playing:
|
||||
self.Stop()
|
||||
|
||||
if position:
|
||||
PosStr = str(datetime.timedelta(seconds = position))
|
||||
#Command = ["/usr/bin/ffmpeg", "-ss", PosStr, "-i", uri, "-acodec", "pcm_s16le", "-ac", "1", "-ar", str(int(self.SampleRate)), "-f", "s16le", "-vn", *args]
|
||||
@ -71,7 +74,13 @@ class FFmpegAudioPlayer():
|
||||
if args:
|
||||
Command += list(args)
|
||||
|
||||
# Reset per-play counters/state in case this instance is reused.
|
||||
self.Seconds = 0.0
|
||||
self.StartedPlaying = None
|
||||
self.StoppedPlaying = None
|
||||
self._byte_remainder = 0
|
||||
self.Playing = True
|
||||
|
||||
if dec_params:
|
||||
Command += dec_params
|
||||
|
||||
@ -172,7 +181,7 @@ class FFmpegAudioPlayer():
|
||||
|
||||
if SecondsElapsed >= self.Seconds:
|
||||
if not self.StoppedPlaying:
|
||||
print("BUFFER UNDERRUN!")
|
||||
self.Master.Logger.warning("BUFFER UNDERRUN")
|
||||
self.Stop(False)
|
||||
return
|
||||
|
||||
@ -180,13 +189,17 @@ class FFmpegAudioPlayer():
|
||||
|
||||
async def _read_stream(self, stream, writer):
|
||||
Started = False
|
||||
|
||||
try:
|
||||
while stream and self.Playing:
|
||||
Data = await stream.read(65536)
|
||||
|
||||
if Data:
|
||||
try:
|
||||
writer.write(Data)
|
||||
await writer.drain()
|
||||
except (ConnectionError, BrokenPipeError, OSError) as ex:
|
||||
self.Master.Logger.warning("Voice socket write failed: %s", ex)
|
||||
break
|
||||
|
||||
Bytes = len(Data)
|
||||
frame_size = SAMPLEBYTES * self.Channels
|
||||
@ -214,13 +227,13 @@ class FFmpegAudioPlayer():
|
||||
else:
|
||||
self.Process = None
|
||||
break
|
||||
|
||||
finally:
|
||||
self.StoppedPlaying = time.time()
|
||||
|
||||
async def _stream_subprocess(self, cmd):
|
||||
if not self.Playing:
|
||||
return
|
||||
|
||||
try:
|
||||
_, self.Writer = await asyncio.open_connection(self.Host[0], self.Host[1])
|
||||
|
||||
Process = await asyncio.create_subprocess_exec(*cmd,
|
||||
@ -230,5 +243,11 @@ class FFmpegAudioPlayer():
|
||||
await self._read_stream(Process.stdout, self.Writer)
|
||||
await Process.wait()
|
||||
|
||||
if self.Seconds == 0.0:
|
||||
if self.Playing:
|
||||
self.Stop(False)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
self.Master.Logger.error(traceback.format_exc())
|
||||
if self.Playing:
|
||||
self.Stop()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user