Spaces:
Runtime error
Runtime error
Update stream_audio.py
Browse files- stream_audio.py +12 -6
stream_audio.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import subprocess
|
| 3 |
from multiprocessing import Process
|
| 4 |
import uvicorn
|
|
@@ -35,6 +36,14 @@ def start_audio_streaming():
|
|
| 35 |
audio_process = Process(target=stream_audio)
|
| 36 |
audio_process.start()
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
@app.get("/")
|
| 39 |
async def read_root():
|
| 40 |
return {"message": "Servidor de Radio M3U8 Activo"}
|
|
@@ -42,12 +51,9 @@ async def read_root():
|
|
| 42 |
@app.get("/stream.m3u8")
|
| 43 |
def get_stream():
|
| 44 |
# Devuelve el archivo M3U8 generado
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
return Response(content=m3u8_content, media_type="application/vnd.apple.mpegurl")
|
| 49 |
-
else:
|
| 50 |
-
return {"error": "No se encuentra el archivo M3U8"}
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
start_audio_streaming()
|
|
|
|
| 1 |
import os
|
| 2 |
+
import time
|
| 3 |
import subprocess
|
| 4 |
from multiprocessing import Process
|
| 5 |
import uvicorn
|
|
|
|
| 36 |
audio_process = Process(target=stream_audio)
|
| 37 |
audio_process.start()
|
| 38 |
|
| 39 |
+
@app.on_event("startup")
|
| 40 |
+
async def startup_event():
|
| 41 |
+
# Espera activa para verificar que el archivo M3U8 esté generado
|
| 42 |
+
while not os.path.exists(hls_output):
|
| 43 |
+
print("Esperando a que se genere el archivo M3U8...")
|
| 44 |
+
time.sleep(1)
|
| 45 |
+
print("Archivo M3U8 generado. Servidor listo para recibir solicitudes.")
|
| 46 |
+
|
| 47 |
@app.get("/")
|
| 48 |
async def read_root():
|
| 49 |
return {"message": "Servidor de Radio M3U8 Activo"}
|
|
|
|
| 51 |
@app.get("/stream.m3u8")
|
| 52 |
def get_stream():
|
| 53 |
# Devuelve el archivo M3U8 generado
|
| 54 |
+
with open(hls_output, "rb") as f:
|
| 55 |
+
m3u8_content = f.read()
|
| 56 |
+
return Response(content=m3u8_content, media_type="application/vnd.apple.mpegurl")
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
start_audio_streaming()
|