So i have the code:
import glob,os import random path = 'C:\\Music\\' aw=[] for infile in glob.glob( os.path.join(path,'*.mp3') ): libr = infile.split('Downloaded',1) aw.append(infile) aww = -1 while 1: aww += 1 print len(aw),aww random.shuffle(aw) awww = aw[aww] os.startfile(awww)
but all it does is go through all of the songs without stopping. I thought if I could find the length of the song that is currently playing, I could use the "time" module to keep going after the song is done with the (sleep) attribute. However, I couldn't find how to get the length of the song on windows. Does anyone know a solution to my probleme?
To determine the file size of an audio file, we have to multiply the bit rate of the audio by its duration in seconds. As a result, we get file size values in terms of kilobits and megabits.
The typical MP3 (an MPEG Layer III, version 1) has 1152 samples per frame and the sample rate is (commonly) 44100 hz. So (1152 / 44100) * 1000 = 26,122449 ms per frame.
You can use mutagen to get the length of the song (see the tutorial):
from mutagen.mp3 import MP3 audio = MP3("example.mp3") print(audio.info.length)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With