Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i Control VLC media player through a Python scripte

so I had this idea of controlling a media player from a python script like VLC for example, but since I am new to Python I don't know how to achieve that, so let me explain what I am looking for is for example, I want to get and set a volume value of VLC from my Python script? I am not asking for a whole code or something like that just some tips to follow and thanks in advance

like image 325
The Wolf Avatar asked Oct 28 '25 19:10

The Wolf


1 Answers

Install python-vlc

pip install python-vlc

Just change the path,your good to go..

from vlc import Instance
import time
import os

class VLC:
    def __init__(self):
        self.Player = Instance('--loop')

    def addPlaylist(self):
        self.mediaList = self.Player.media_list_new()
        path = r"C:\Users\dell5567\Desktop\engsong"
        songs = os.listdir(path)
        for s in songs:
            self.mediaList.add_media(self.Player.media_new(os.path.join(path,s)))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
    def play(self):
        self.listPlayer.play()
    def next(self):
        self.listPlayer.next()
    def pause(self):
        self.listPlayer.pause()
    def previous(self):
        self.listPlayer.previous()
    def stop(self):
        self.listPlayer.stop()

Create a object

player = VLC()

Add playlist

player.addPlaylist()

Play the song

player.play()
time.sleep(9)

Play the next song

player.next()
time.sleep(9)

Pause the song

player.pause()
time.sleep(9)

Resume the song

player.play()
time.sleep(9)

Previous song

player.previous()
time.sleep(9)

Stop the song

player.stop()
like image 89
Pramod Avatar answered Oct 31 '25 10:10

Pramod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!