How to close program in python opened by os.system()?

1.5k Views Asked by At

In python 3.4 , I was trying to open a "wav" file using vlc in Linux. Here is my code:

import os,time

os.system("cvlc audio/some.wav")
time.sleep(3)  #audio was one and half sec
a = 3+3
print (a)

It plays the audio but then doesn’t do the rest. What should I do to make it do them? more precisely what should I do to close the vlc program?

With solving the problem it will also be very grateful to know is there any easier way to play audio within the code specifically in python 3.4? (platform independent code will be even more grateful!)

1

There are 1 best solutions below

0
On BEST ANSWER

So the VLC player doesn't exit. The VLC player has a command line argument to close the player once the song/video has been played.

Playlist
These options define the behavior of the playlist. Some of them can be overridden in the playlist dialog box.

  --play-and-exit, --no-play-and-exit
                             Play and exit (default disabled)

Source: https://wiki.videolan.org/VLC_command-line_help


Can you try the following?

os.system("cvlc audio/some.wav --play-and-exit")