Apr-12-2020, 11:47 PM
Hello, I am trying to write a script that calls a program to play audio and then restart the program so often.
However the program is not being killed and respawned?!
However the program is not being killed and respawned?!
""" Playback an audio stream. Here we want to playback audio untill the user presses ctrl+c. If we do not restart our playback process every three hours the server providing the audio may start giving us silence. """ import random import subprocess import time def make_url(): """Append a random value to urls end.""" rnd = str(random.randrange(1000000)) url_with_rnd = "https://mediaserver3.afa.net:8443/talk.mp3" + "?" + rnd return url_with_rnd MPV_EXE = "F:/z0bin/mpv/mpv-0-32-0/mpv.com" while True: URL = make_url() ARGS = [ MPV_EXE, "--no-config", "--input-conf=./input.conf", "--audio-device=wasapi/{9c3e3659-8106-448c-a9b3-93881bbbfadc}", "--audio-exclusive=no", "--input-media-keys=no", "--no-input-default-bindings", "--no-video", URL, ] with subprocess.run(ARGS) as proc: # Use 30 seconds to test if exiting works. # Else we'd use 10800 seconds. TIME_TO_EXIT = time.time() + 30 while proc.poll() is not None: if time.time() > TIME_TO_EXIT: proc.terminate() print("") print("We exited MPV.") print("") break time.sleep(1) else: print("") print("MPV exited itself.") print("")