Hi I am looking for a method that either uses pygame.mixer..music or
pygame.mixer.Sound.

I am looking for a method that will play all the songs in a listofsongs
displayed in the GUI as listbox

I have got the playAll method playing one song then it stops.  Attached is
the file and a compressed playList
 PlayListOne.zip
<https://drive.google.com/file/d/1firHEmwuRe4xmOYFpTWa326850FZ4CSJ/view?usp=drive_web>

-- 
Dave Merrick

Email [email protected]

Ph   03 216 2053

Cell 027 3089 169
import os
import pygame
import tkinter as tk
from tkinter.filedialog import Tk, Button, askdirectory, Label, Listbox, LEFT, 
RIGHT
#from mutagen.id3 import ID3

root = Tk()

listofsongs = []
formattedlist = []
realnames = []

index = 0

def directorychoose():
    filename = askdirectory()
    os.chdir(filename)

    for file in os.listdir(filename):
        if file.endswith(".mp3"):
            print('file is ',file)
            songName = file.split('.')[0]
            #print('songName is ',songName)
            realnames.append(songName)

            #################################

            # This part doesn't work
            
            #realdir = os.path.realpath(file)
            #audio = ID3(realdir)
            #realnames.append(audio['TIT2'].text[0])

            #################################
            
            listofsongs.append(file)

    for file in realnames:
        formattedlist.append(file)
        #formattedlist.append(file + "\n")

    pygame.mixer.init()
    pygame.mixer.music.load(listofsongs[0])
    pygame.mixer.music.play()


def nextsong(event):
    global index
    index += 1
    pygame.mixer.music.load(listofsongs[index])
    pygame.mixer.music.play()


def prevsong(event):
    global index
    index -= 1
    pygame.mixer.music.load(listofsongs[index])
    pygame.mixer.music.play()


def stopsong(event):
    pygame.mixer.music.stop()


directorychoose()

label = Label(root, text='Music player')
label.pack()

listbox = Listbox(root)

for item in formattedlist:
    #print('item is ',item)
    listbox.insert(tk.END,item)
    #listbox.insert(0, item)

listbox.pack()

button = Button(root, text='Next')
button.pack(side=RIGHT)
button2 = Button(root, text='Prev')
button2.pack(side=LEFT)
stopbutton = Button(root, text='Stop')
stopbutton.pack()

button.bind("<Button-1>", nextsong)
button2.bind("<Button-1>", prevsong)
stopbutton.bind("<Button-1>", stopsong)

root.mainloop()
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users

Reply via email to