Skip to content

Python VLC

Python VLC is a library to control vlc from python.

There is not usable online documentation, you'll have to go through the help(<component>) inside the python console.

Installation

pip install python-vlc

Usage

Basic usage

You can create an instance of the vlc player with:

import vlc

player = vlc.MediaPlayer('path/to/file.mp4')

The player has the next interesting methods:

  • play(): Opens the program and starts playing, if you've used pause it resumes playing.
  • pause(): Pauses the video
  • stop(): Closes the player.
  • set_fulscreen(1): Sets to fullscreen if you pass 0 as argument it returns from fullscreen.
  • set_media(vlc.Media('path/to/another/file.mp4')): Change the reproduced file. It can even play pictures!

If you want more control, it's better to use an vlc.Instance object to work with.

Configure the instance

instance = Instance('--loop')

Reproduce many files

First you need to create a media list:

media_list = instance.media_list_new()
path = "/path/to/directory"
files = os.listdir(path)
for file_ in files:
    media_list.add_media(instance.media_new(os.path.join(path,s)))

Then create the player:

media_player = instance.media_list_player_new()
media_player.set_media_list(media_list)

Now you can use player.next() and player.previous().

Set playback mode

media_player.set_playback_mode(vlc.PlaybackMode.loop)

There are the next playback modes:

  • default
  • loop
  • repeat

References