0

I had made a music player where I want to make a infinite loop which will play after song will end and the song is a random song(a song played from a selected folder) so I want to make loop on random_music(local variable). I had tried much but I can't make this loop.

Please help me to solve this problem

Here is my code

random_music = ''
mfile=''
def Play(event=None):
    global random_music, mfile
    if (shuffleUnshuffleBtn['text'] == ''): 
        mfile= MUSIC_FILE+'/../'
        print("Shuffle")
        print(mfile)
        songs =os.listdir(mfile)
        noOfSongs=len(songs)
        ListOfSongsInDir = [i for i in range(1, noOfSongs)]
        print(songs)
        print(len(songs))
        print(ListOfSongsInDir)
        random_music = random.choice(songs)
        while (progressbar_music_starttime==progressbar_music_startend):
            print(random.choice(songs))
            #random_music = random.choice(songs)
            # sleep()
        print(random_music)
        c=(os.path.join(mfile, random_music))
            # i+=1
            
        mixer.init()
        # ad=audiotrack.get()
        
        mixer.music.load(c)
        print(c)
        progressbar_Ibl.place()
        mixer.music.play()
        progressbar_music_label.place()
        song=MP3(mfile+random_music)

Here MUSIC_FILE is a song that select by user

Sam Mason
  • 15,216
  • 1
  • 41
  • 60
  • you can use `mixer.music.play(loops)` where loops is how many times the music should be played I also suggest looking at pygame [mixer docs](https://www.pygame.org/docs/ref/mixer.html) for more information. Also you may want to use `.get_busy()` method to check if mixer is mixing (more info in docs). – Matiiss Nov 01 '20 at 18:03
  • Sir I had tried it but it don't works in my script. –  Nov 01 '20 at 18:26
  • can you show the whole code? – Matiiss Nov 01 '20 at 19:03
  • Sir do you want whole script of my code? –  Nov 02 '20 at 04:24
  • stack overflow do not supports whole code due to the code is too long, sir please provide me some other media –  Nov 02 '20 at 04:26
  • see https://stackoverflow.com/help/how-to-ask for general info and https://stackoverflow.com/help/minimal-reproducible-example for what is a good amount of code to include – Sam Mason Nov 02 '20 at 09:53

0 Answers0