02-ago: [proyecto] vigilancia - fix apagado prematuro: esperar SOLO la media con nuestra URL (content_id) en reproduccion y fin, no estados viejos de la sirena
This commit is contained in:
@@ -109,16 +109,14 @@ def _url_audio(texto, nombre="anuncio.mp3"):
|
||||
return f"http://{_ip_lan()}:{config.GOOGLE_TV_PUERTO}/{os.path.basename(ruta)}"
|
||||
|
||||
|
||||
def _esperar_reproduccion(cast, timeout=15):
|
||||
"""Espera a que la reproduccion realmente empiece (PLAYING/BUFFERING)."""
|
||||
def _esperar_reproduccion(cast, url, timeout=20):
|
||||
"""Espera a que NUESTRA media empiece (PLAYING/BUFFERING) por content_id."""
|
||||
mc = cast.media_controller
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < timeout:
|
||||
try:
|
||||
st = mc.status
|
||||
if st.player_state in ("PLAYING", "BUFFERING"):
|
||||
return True
|
||||
if st.player_state == "IDLE" and st.idle_reason == "FINISHED":
|
||||
if st.content_id == url and st.player_state in ("PLAYING", "BUFFERING"):
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
@@ -126,22 +124,19 @@ def _esperar_reproduccion(cast, timeout=15):
|
||||
return False
|
||||
|
||||
|
||||
def _esperar_fin(cast, timeout=120):
|
||||
"""Espera a que el audio termine de verdad (IDLE + idle_reason FINISHED)."""
|
||||
def _esperar_fin(cast, url, timeout=120):
|
||||
"""Espera a que NUESTRA media termine (IDLE + FINISHED) por content_id."""
|
||||
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" and st.idle_reason == "FINISHED":
|
||||
if st.content_id == url and st.player_state == "IDLE" and st.idle_reason == "FINISHED":
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(1)
|
||||
return visto_playing
|
||||
return False
|
||||
|
||||
|
||||
def _generar_pitido():
|
||||
@@ -216,10 +211,9 @@ def _url_silencio():
|
||||
|
||||
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)
|
||||
_esperar_reproduccion(c, url)
|
||||
return _esperar_fin(c, url)
|
||||
|
||||
|
||||
def anuncio_en_teles(texto):
|
||||
|
||||
Reference in New Issue
Block a user