I've been trying to find a way to control the vlc playback from within a Python script. Ideally, I'd like to use the built in vlc button controls for play, pause, stop, and, rewind. I've read some posts that implied that those controls are not available when run from a script. I then decided to use the keyboard shortcuts to control the video. My sample code is below.
def pauseVideo(event, player):
i = 0
# Play a video.
def playVideo(path):
global events
try:
#vlcCommand = "/snap/bin/vlc " + path + " --fullscreen"
#os.system(vlcCommand)
instance = vlc.Instance()
mediaPlayer = instance.media_player_new()
media = instance.media_new_location(path)
mediaPlayer.set_media(media)
# creating vlc media player object
#mediaPlayer = vlc.MediaPlayer(path)
# setting full screen status
#mediaPlayer.set_fullscreen(True)
#mediaPlayer.video_set_mouse_input(True)
events = mediaPlayer.event_manager()
# start playing video
mediaPlayer.play()
events.event_attach(vlc.EventType.MediaPlayerPaused, pauseVideo)
#while():
# continue
except Exception as e:
error = "Exception from 'playVideo':" + sys.exc_info()[0] + " occurred."
ReportError(error)
Since I could not find a way to use the standard buttons, I thought I might be able to respond to the keyboard events. I haven't been able to get it to work. When I run the code, my event is not triggered.
Can anyone point me in the right direction to handle vlc events in Python?