CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python-vlc

VLC bindings for Python providing comprehensive multimedia functionality through LibVLC API.

Pending
Overview
Eval results
Files

media-lists.mddocs/

Media Lists and Playlists

Media list management for creating and controlling playlists with sequential or custom playback modes. These classes enable building media applications with playlist functionality and batch media operations.

Capabilities

Media List Management

The MediaList class provides comprehensive media collection management with adding, removing, and accessing media items.

class MediaList:
    def __init__(self, instance=None):
        """Create a new media list.
        
        Args:
            instance (Instance, optional): VLC instance to use
        """
        ...
    
    def get_instance(self):
        """Get the instance associated with this media list.
        
        Returns:
            Instance: The LibVLC instance
        """
        ...
    
    def add_media(self, media):
        """Add a media item to the list.
        
        Args:
            media (Media): Media object to add
            
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def insert_media(self, media, index):
        """Insert a media item at a specific position.
        
        Args:
            media (Media): Media object to insert
            index (int): Position to insert at
            
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def remove_index(self, index):
        """Remove a media item at a specific position.
        
        Args:
            index (int): Position of item to remove
            
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def count(self):
        """Get the number of items in the media list.
        
        Returns:
            int: Number of media items
        """
        ...
    
    def item_at_index(self, index):
        """Get the media item at a specific position.
        
        Args:
            index (int): Position of item to retrieve
            
        Returns:
            Media: Media object at position, or None if invalid index
        """
        ...
    
    def index_of_item(self, media):
        """Get the index of a specific media item.
        
        Args:
            media (Media): Media object to find
            
        Returns:
            int: Index of media item, or -1 if not found
        """
        ...
    
    def is_readonly(self):
        """Check if the media list is read-only.
        
        Returns:
            bool: True if read-only, False otherwise
        """
        ...
    
    def lock(self):
        """Lock the media list for thread-safe access."""
        ...
    
    def unlock(self):
        """Unlock the media list."""
        ...
    
    def event_manager(self):
        """Get the event manager for this media list.
        
        Returns:
            EventManager: Event manager for this media list
        """
        ...
    
    def release(self):
        """Release the media list."""
        ...

Media List Player Control

The MediaListPlayer class provides playlist playback control with navigation and playback mode management.

class MediaListPlayer:
    def __init__(self, instance=None):
        """Create a new media list player.
        
        Args:
            instance (Instance, optional): VLC instance to use
        """
        ...
    
    def get_instance(self):
        """Get the instance associated with this media list player.
        
        Returns:
            Instance: The LibVLC instance
        """
        ...
    
    def release(self):
        """Release the media list player."""
        ...
    
    def event_manager(self):
        """Get the event manager for this media list player.
        
        Returns:
            EventManager: Event manager for this media list player
        """
        ...
    
    def set_media_player(self, media_player):
        """Set the media player to use for playback.
        
        Args:
            media_player (MediaPlayer): Media player instance
        """
        ...
    
    def get_media_player(self):
        """Get the current media player.
        
        Returns:
            MediaPlayer: Current media player or None
        """
        ...
    
    def set_media_list(self, media_list):
        """Set the media list to play.
        
        Args:
            media_list (MediaList): Media list to play
        """
        ...
    
    def play(self):
        """Start or resume playback of the media list.
        
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def pause(self):
        """Pause playback of the media list."""
        ...
    
    def stop(self):
        """Stop playback of the media list."""
        ...
    
    def next(self):
        """Play the next item in the media list.
        
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def previous(self):
        """Play the previous item in the media list.
        
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def set_playback_mode(self, mode):
        """Set the playback mode.
        
        Args:
            mode (PlaybackMode): Playback mode to set
        """
        ...
    
    def get_state(self):
        """Get the current player state.
        
        Returns:
            State: Current player state
        """
        ...
    
    def play_item_at_index(self, index):
        """Play a specific item in the media list.
        
        Args:
            index (int): Index of item to play
            
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def play_item(self, media):
        """Play a specific media item in the media list.
        
        Args:
            media (Media): Media item to play
            
        Returns:
            int: 0 on success, -1 on error
        """
        ...
    
    def get_media_player(self):
        """Get the media player used by this list player.
        
        Returns:
            MediaPlayer: The media player instance
        """
        ...

Playback Modes

Enumeration for media list playback modes.

class PlaybackMode:
    """Media list playback modes."""
    Default = 0
    Loop = 1
    Repeat = 2

Media List Events

Event types specific to media list operations.

class MediaListEventType:
    """Media list event types."""
    MediaListItemAdded = 0x200
    MediaListWillAddItem = 0x201
    MediaListItemDeleted = 0x202
    MediaListWillDeleteItem = 0x203
    MediaListEndReached = 0x204

Media List Player Events

Event types specific to media list player operations.

class MediaListPlayerEventType:
    """Media list player event types."""
    MediaListPlayerPlayed = 0x400
    MediaListPlayerNextItemSet = 0x401
    MediaListPlayerStopped = 0x402

Usage Examples

Basic Playlist Creation

import vlc

# Create instance and media list
instance = vlc.Instance()
media_list = instance.media_list_new()

# Add media files to the list
media1 = instance.media_new('/path/to/song1.mp3')
media2 = instance.media_new('/path/to/song2.mp3')
media3 = instance.media_new('/path/to/song3.mp3')

media_list.add_media(media1)
media_list.add_media(media2)  
media_list.add_media(media3)

print(f"Playlist has {media_list.count()} items")

# Get item at specific position
first_item = media_list.item_at_index(0)
if first_item:
    print(f"First item: {first_item.get_mrl()}")

Media List Player with Navigation

import vlc
import time

# Create media list and populate it
instance = vlc.Instance()
media_list = instance.media_list_new()

songs = ['/path/to/song1.mp3', '/path/to/song2.mp3', '/path/to/song3.mp3']
for song_path in songs:
    media = instance.media_new(song_path)
    media_list.add_media(media)

# Create media list player
list_player = instance.media_list_player_new()
list_player.set_media_list(media_list)

# Start playback
list_player.play()
print("Playing playlist...")

# Wait a bit, then navigate
time.sleep(5)

# Skip to next song
print("Skipping to next...")
list_player.next()

time.sleep(5)

# Go back to previous song
print("Going to previous...")
list_player.previous()

time.sleep(5)

# Play specific item by index
print("Playing item at index 2...")
list_player.play_item_at_index(2)

Playlist Management Operations

import vlc

instance = vlc.Instance()
media_list = instance.media_list_new()

# Add multiple media files
media_files = [
    '/path/to/video1.mp4',
    '/path/to/video2.mp4', 
    '/path/to/video3.mp4'
]

for file_path in media_files:
    media = instance.media_new(file_path)
    media_list.add_media(media)

print(f"Initial count: {media_list.count()}")

# Insert media at specific position
new_media = instance.media_new('/path/to/inserted_video.mp4')
media_list.insert_media(new_media, 1)  # Insert at position 1
print(f"After insert: {media_list.count()}")

# Remove media at specific position
media_list.remove_index(2)  # Remove item at position 2
print(f"After removal: {media_list.count()}")

# List all items in the playlist
print("Current playlist:")
for i in range(media_list.count()):
    item = media_list.item_at_index(i)
    if item:
        print(f"  {i}: {item.get_mrl()}")

# Find index of specific media
search_media = media_list.item_at_index(0)
if search_media:
    index = media_list.index_of_item(search_media)
    print(f"First item is at index: {index}")

Playback Modes

import vlc

instance = vlc.Instance()
media_list = instance.media_list_new()

# Add some media
for i in range(3):
    media = instance.media_new(f'/path/to/song{i+1}.mp3')
    media_list.add_media(media)

# Create list player
list_player = instance.media_list_player_new()
list_player.set_media_list(media_list)

# Set different playback modes
print("Setting loop mode...")
list_player.set_playback_mode(vlc.PlaybackMode.Loop)
list_player.play()

# The playlist will now loop continuously
# Change to repeat mode (repeat current item)
# list_player.set_playback_mode(vlc.PlaybackMode.Repeat)

# Change to default mode (play once through)
# list_player.set_playback_mode(vlc.PlaybackMode.Default)

Media List Events

import vlc
import time

def on_item_added(event):
    print(f"Item added to media list")

def on_item_deleted(event):
    print(f"Item deleted from media list")

def on_list_ended(event):
    print("Reached end of media list")

def on_next_item_set(event):
    print("Next item set in playlist")

def on_list_player_stopped(event):
    print("Media list player stopped")

# Create media list with event handling
instance = vlc.Instance()
media_list = instance.media_list_new()

# Attach media list events
list_em = media_list.event_manager()
list_em.event_attach(vlc.EventType.MediaListItemAdded, on_item_added)
list_em.event_attach(vlc.EventType.MediaListItemDeleted, on_item_deleted)
list_em.event_attach(vlc.EventType.MediaListEndReached, on_list_ended)

# Create list player with events
list_player = instance.media_list_player_new()
list_player.set_media_list(media_list)

# Attach list player events
player_em = list_player.event_manager()
player_em.event_attach(vlc.EventType.MediaListPlayerNextItemSet, on_next_item_set)
player_em.event_attach(vlc.EventType.MediaListPlayerStopped, on_list_player_stopped)

# Add media (triggers event)
media = instance.media_new('/path/to/song.mp3')
media_list.add_media(media)

# Start playback
list_player.play()
time.sleep(10)

# Remove media (triggers event)
media_list.remove_index(0)

# Stop playback (triggers event)
list_player.stop()

Thread-Safe Media List Operations

import vlc
import threading
import time

def worker_thread(media_list, instance):
    """Worker thread that modifies the media list"""
    for i in range(5):
        media_list.lock()  # Lock for thread safety
        try:
            media = instance.media_new(f'/path/to/file{i}.mp3')
            media_list.add_media(media)
            print(f"Added media {i}")
        finally:
            media_list.unlock()  # Always unlock
        time.sleep(1)

# Create media list
instance = vlc.Instance()
media_list = instance.media_list_new()

# Start worker thread
thread = threading.Thread(target=worker_thread, args=(media_list, instance))
thread.start()

# Main thread can safely read the list
while thread.is_alive():
    media_list.lock()
    try:
        count = media_list.count()
        print(f"Current count: {count}")
    finally:
        media_list.unlock()
    time.sleep(0.5)

thread.join()
print(f"Final count: {media_list.count()}")

Install with Tessl CLI

npx tessl i tessl/pypi-python-vlc

docs

audio-control.md

core-playback.md

data-structures.md

discovery-renderers.md

event-system.md

index.md

low-level-functions.md

media-lists.md

video-control.md

tile.json