简体   繁体   中英

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

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

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'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM