import os
from os import listdir
import pyglet
import random
from pyglet import app
from pyglet import window

song_list=[]   ##empty list to store the list of songs

for file in os.listdir("."):
	if ".mp3" in file:
		song_list.append(file)           ##listdir will list all files and even the subdirectories, so I just 
										 ##used a workaround to add only the mp3 files


player = pyglet.media.Player()           ##player object has the option of queueing

random.shuffle(song_list)
random.shuffle(song_list)
random.shuffle(song_list)               
random.shuffle(song_list)   ##making the playlist random

for song in song_list:
	
	audio = pyglet.resource.media(song)
	player.queue(audio)



player.play()
pyglet.app.run()



	





	





	
	

	

import os
import pyglet
import random

# empty list to store the list of songs
song_list = []

for file in os.listdir("."):
    if ".wav" in file:
        # listdir will list all files and subdirectories, so I just used a workaround to add only the .wav files
        # EDIT: To use .mp3 files, you will have to use AVbin otherwise this error occurs...
            # pyglet.media.riff.WAVEFormatException: AVbin is required to decode compressed media
        song_list.append(file)

# player object has the option of queueing
player = pyglet.media.Player()

# making the playlist random
random.shuffle(song_list)
random.shuffle(song_list)
random.shuffle(song_list)               
random.shuffle(song_list)

for song in song_list:
    audio = pyglet.resource.media(song)
    player.queue(audio)

player.play()
pyglet.app.run()

change .mp3 file reader to .wav; cleaned comments and format