title: python script to play audio from RaspberryPi using vlc
body: <p>I am tyring to get a list of songs running on my RaspberryPi at the same time every day. For that I have written a python script and plan to run that as a cronjob.</p>
  <p>The script I have written is below.</p>
  <pre><code>import vlc
  import glob
  import time
  
  base_folder = '/home/pi/Music/'
  
  
  def play_song(song):
      player = vlc.MediaPlayer(song)
      player.play()
  
      
  def add_media(player, media_list, playlist):
      for song in playlist:
          print('sing &quot; {0}'.format(song))
          media = player.media_new(song)    
          media_list.add_media(media)
          
      media_player.set_media_list(media_list)
  
    
  playlist = glob.glob(base_folder + &quot;/&quot; + &quot;*.mp3&quot;)
  media_player = vlc.MediaListPlayer()
  player = vlc.Instance()    
  media_list = vlc.MediaList()
  add_media(player, media_list, playlist)
  </code></pre>
  <p>I have one issue with the above program.</p>
  <p>When I run the python program from <code>Thonny</code> which is the default python IDE for RaspberryPi it works. (i.e it plays the songs). However when I run this from the command line as</p>
  <pre><code>python3 audioplayer.py
  </code></pre>
  <p>it exits without playing the songs. How do I make it play the songs while running from command line.</p>