feat: use python-vlc to play a video
This commit is contained in:
31
player.py
Normal file
31
player.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import vlc
|
||||
import time
|
||||
|
||||
# Path to your video file
|
||||
video_path = "/home/wancat/mind-blowing.mp4"
|
||||
|
||||
# Creating a VLC instance
|
||||
player = vlc.Instance()
|
||||
|
||||
# Creating a Media Player
|
||||
media_player = player.media_player_new()
|
||||
|
||||
# Creating a new Media
|
||||
media = player.media_new(video_path)
|
||||
|
||||
# Setting media to media player
|
||||
media_player.set_media(media)
|
||||
|
||||
# Play the media
|
||||
media_player.play()
|
||||
|
||||
# Wait for the video to play
|
||||
time.sleep(10) # Waits for 5 seconds; adjust or use a different method to wait for the video to finish
|
||||
|
||||
# Stop playing
|
||||
media_player.stop()
|
||||
|
||||
# Note: The time.sleep() here is just to prevent the script from ending immediately.
|
||||
# For a real application, you'll need a more robust way to check if the video is still playing.
|
||||
# This could be done by polling the media player's state or setting up event handlers.
|
||||
|
||||
Reference in New Issue
Block a user