Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close/exit/quit Vlc Player in python on Ubuntu

Tags:

python

ubuntu

vlc

I am trying to write a simple program in Python on Ubuntu that will close/exit/quit VLC Player when playing video has completed.

Can you please guide me that what should I add in my program to get my required result.

import io,sys,os,subprocess
from tkFileDialog import askopenfilename
global process
name= askopenfilename(filetypes=[("Video Files","*.h264")])
myprocess = subprocess.call(['vlc',name])

Thank you


1 Answers

Use VLC's --play-and-exit command line option as so:

subprocess.call(['vlc',name,'--play-and-exit'])

so your final code would look like:

import io,sys,os,subprocess
from tkFileDialog import askopenfilename
global process
name= askopenfilename(filetypes=[("Video Files","*.h264")])
subprocess.call(['vlc',name,'--play-and-exit'])

[Note:] You may have to set shell to True or False for it to work properly as so:

shell_value = False  # or True
subprocess.call(['vlc',name,'--play-and-exit'], shell=shell_value)

[Alternative:] You can also instead include vlc://quit as the last 'file' to play as so:

subprocess.call(['vlc',name,'vlc://quit'])
like image 198
Yatharth Agarwal Avatar answered Dec 15 '25 22:12

Yatharth Agarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!