ca0a880c803daca1fa15cf3cf95bccae9684e45c
VLChan
A Python video player using VLC SDK with synchan server timecode synchronization.
Features
- VLC-based video playback with full media support
- Real-time synchronization with synchan server
- Reactive programming with RxPY
- Automatic timecode correction
- Playback state synchronization
- Volume and fullscreen controls
Installation
-
Install VLC media player on your system:
- Ubuntu/Debian:
sudo apt install vlc - macOS:
brew install vlc - Windows: Download from videolan.org
- Ubuntu/Debian:
-
Install the Python package:
cd vlchan poetry install
Usage
Basic Usage
from vlchan import VLChanPlayer
# Create player with video file
player = VLChanPlayer(
synchan_url="http://localhost:3000",
video_path="/path/to/video.mp4"
)
# Start synchronization
player.start_sync()
# Play video
player.play()
# Clean up when done
player.cleanup()
Advanced Usage
from vlchan import VLChanPlayer
def on_state_change(state):
print(f"Synchan state: playing={state.playing}, time={state.currentTime:.2f}s")
# Create player
player = VLChanPlayer("http://localhost:3000", "video.mp4")
# Set up state change callback
player.on_state_change = on_state_change
# Start synchronization
player.start_sync()
# Control playback
player.play()
player.pause()
player.seek(120.5) # Seek to 2 minutes 0.5 seconds
# Adjust settings
player.set_volume(80)
player.set_fullscreen(True)
# Get current state
print(f"Position: {player.get_position():.2f}s")
print(f"Duration: {player.get_duration():.2f}s")
print(f"Playing: {player.is_playing()}")
Command Line Usage
# Play video with synchan sync
poetry run python -m vlchan.player video.mp4
# Use custom synchan server
poetry run python -m vlchan.player video.mp4 http://192.168.1.100:3000
API Reference
VLChanPlayer
Constructor
VLChanPlayer(synchan_url: str, video_path: Optional[str])synchan_url: URL of the synchan server (default: "http://localhost:3000")video_path: Path to video file to load
Methods
load_video(video_path: str): Load a video filestart_sync(): Start synchronization with synchan serverstop_sync(): Stop synchronizationplay(): Start playbackpause(): Pause playbackstop(): Stop playbackseek(time_seconds: float): Seek to specific timeset_volume(volume: int): Set volume (0-100)get_volume() -> int: Get current volumeset_fullscreen(fullscreen: bool): Toggle fullscreenget_position() -> float: Get current position in secondsget_duration() -> float: Get video duration in secondsis_playing() -> bool: Check if playingcleanup(): Clean up resources
Properties
on_state_change: Callback for synchan state changes
SynchanState
Data class containing synchronization state:
playing: bool: Whether video should be playingcurrentTime: float: Current time position in secondsduration: float: Total duration in secondsloop: bool: Whether video should looplatency: float: Network latency in seconds
Synchronization
The player automatically synchronizes with the synchan server:
- Playback State: Play/pause commands are synchronized
- Time Position: Video seeks to match synchan timecode
- Threshold: Only seeks if time difference exceeds 100ms
- Reconnection: Automatically attempts to reconnect on connection loss
Requirements
- Python 3.11+
- VLC media player
- Synchan server running
Dependencies
python-vlc: VLC Python bindingsreactivex: Reactive programmingpython-socketio: WebSocket client for synchanrequests: HTTP client for synchan API
Development
# Install development dependencies
poetry install --with dev
# Run linting
poetry run ruff check .
# Run type checking
poetry run mypy vlchan/
Description
Languages
Python
95.8%
Makefile
4.2%