02-ago: [proyecto] vigilancia - fix: esperar a que cada audio empiece (PLAYING) antes de dar por terminado, para no cortar sirena ni mensaje
This commit is contained in:
@@ -92,14 +92,38 @@ def _url_audio(texto, nombre="anuncio.mp3"):
|
||||
return f"http://{_ip_lan()}:{config.GOOGLE_TV_PUERTO}/{os.path.basename(ruta)}"
|
||||
|
||||
|
||||
def _esperar_fin(cast, timeout=90):
|
||||
def _esperar_reproduccion(cast, timeout=15):
|
||||
"""Espera a que la reproduccion realmente empiece (PLAYING/BUFFERING)."""
|
||||
mc = cast.media_controller
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < timeout:
|
||||
try:
|
||||
st = mc.status
|
||||
if st.player_state == "IDLE":
|
||||
if st.player_state in ("PLAYING", "BUFFERING"):
|
||||
return True
|
||||
if st.player_state == "IDLE" and st.idle_reason == "FINISHED":
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(1)
|
||||
return False
|
||||
|
||||
|
||||
def _esperar_fin(cast, timeout=90):
|
||||
"""Espera a que termine (IDLE) despues de haber empezado a reproducir."""
|
||||
mc = cast.media_controller
|
||||
t0 = time.time()
|
||||
visto_playing = False
|
||||
while time.time() - t0 < timeout:
|
||||
try:
|
||||
st = mc.status
|
||||
if st.player_state == "PLAYING":
|
||||
visto_playing = True
|
||||
if st.player_state == "IDLE":
|
||||
if st.idle_reason == "FINISHED":
|
||||
return True
|
||||
if visto_playing:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(1)
|
||||
@@ -180,6 +204,7 @@ def _reproducir_y_esperar(c, url, content_type, titulo, desc):
|
||||
c.media_controller.play_media(url, content_type, title=titulo)
|
||||
c.media_controller.block_until_active(timeout=10)
|
||||
print(f"[Voz] {desc}")
|
||||
_esperar_reproduccion(c)
|
||||
return _esperar_fin(c)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user