3

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

Fahadkalis
  • 2,971
  • 8
  • 23
  • 40
  • You can kill/terminate the process with myprocess.terminate() and myprocess.kill() respectively. But I don't know how you would go about checking whether VLC has finished playing a video. One of my initial thoughts is to create a VLC plugin(using the python VLC API?) and somehow send a notification from that to your python program when the playback is stopped, but that has the inherent problem that if you have another vlc window open playing a video when that video stops a notification will also get sent. – tom Dec 30 '14 at 20:19
  • @username_unavailable I tried both commands but these are not effective... still VLC Player is open –  Dec 30 '14 at 20:23
  • possible duplicate of [Play video file with VLC, then quit VLC](http://stackoverflow.com/questions/10249261/play-video-file-with-vlc-then-quit-vlc) – Yatharth Agarwal Dec 30 '14 at 20:30

1 Answers1

4

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'])
Yatharth Agarwal
  • 4,385
  • 2
  • 24
  • 53