Check if vlc is play sound if not restart the vlc media player

i want help if it possible i have in my company a streaming radio and play the music on my client with vlc media player last version of vlc i have all pc of my client with windows 10. my problem is some time i loose connection and the client don’t start again if the server it is ok. now i need a script in python to check if audio is playing if not restart the vlc media player and open the file again. my file is in the same folder on all pc C:\music\music.pls

Python isn’t magic. You’ll need a way to communicate with VLC. I recommend researching that part first, as it will tell you exactly what you can and can’t do.

(I happen to know that you acn do a LOT, but you’ll need to check for yourself.)

with my friends i realized this script and work with mp3 file but dont work with .pls file

import pyaudio
import vlc

# Open the VLC player with the playlist file
media = vlc.MediaPlayer("music.mp3")

# Set up PyAudio to listen for audio
p = pyaudio.PyAudio()

while True:
    # Check if there is any audio being played
    if p.get_default_output_device_info()['defaultSampleRate'] == 0:
        # Close VLC and reopen the playlist file
        media = vlc.MediaPlayer("music.mp3")


Have any Idea what to change ? to work with .pls file

What does “dont work with .pls file” mean? What happens when you try?

because this code find the source of file on this machine and play .mp3 because it is on the same pc and the pls file have a link inside and stream from server.
this is an example of one script i found in internet and work with pls file

import requests
import vlc
from time import sleep
urls = [

playlists = set(['pls','m3u'])

Instance = vlc.Instance()

for url in urls:
    ext = (url.rpartition(".")[2])[:3]
    test_pass = False    
        if url[:4] == 'file':
            test_pass = True
            r = requests.get(url, stream=True)
            test_pass = r.ok
    except Exception as e:
        print('failed to get stream: {e}'.format(e=e))
        test_pass = False
        if test_pass:
            print('Sampling for 15 seconds')
            player = Instance.media_player_new()
            Media = Instance.media_new(url)
            Media_list = Instance.media_list_new([url])
            if ext in playlists:
                list_player = Instance.media_list_player_new()
                if == -1:
                    print ("Error playing playlist")
                if == -1:
                    print ("Error playing Stream")
            if ext in playlists:

            print('error getting the audio')

i change the paths of this script and play my playlist but i can’t understand this code to play normal and if not stream it is coming restart the playlist.