目录中的项目以随机顺序添加,但在程序中产生了问题
The items from directory are added in a random order but it is created problems in the programme
播放列表框中的项目在选择特定歌曲时以随机顺序加载,播放错误的歌曲。
尝试加载不同的文件编解码器
尝试使用代码反转加载顺序:playlist.revrse
#Suspected Problematic Code:
playlist = []
def bfolder():
global filenamepath
global directory
global index
folder = filedialog.askdirectory()
os.chdir(folder)
for filename in os.listdir(folder):
if filename.endswith(".mp3") or filename.endswith(".wav") or filename.endswith("flac") or filename.endswith(".ogg") or filename.endswith(".Mp3") or filename.endswith(".Wav") or filename.endswith(".Flac") or filename.endswith(".Ogg") or filename.endswith(".MP3") or filename.endswith(".WAV") or filename.endswith(".FLAC") or filename.endswith(".OGG"):
pg.mixer.music.queue(filename)
filename = os.path.basename(filename)
index = 0
playlist.insert(index, filename)
playlist.reverse()
playlistbox.insert('end', filename)
index +=1
updatelabel()
def updatelabel():
global index
global playlist
v.set(playlist)
#This is probably not required but here is the code used for playbutton:
def play_button():
global paused
if paused:
selected=playlistbox.curselection()
selected = int(selected[0])
play= playlist[selected]
pg.mixer.music.unpause()
statusbar['text']=os.path.basename(play),"Resumed"
paused = FALSE
else:
try:
stop_button()
time.sleep(1)
selected=playlistbox.curselection()
selected = int(selected[0])
play= playlist[selected]
pg.mixer.music.load(play)
pg.mixer.music.play()
statusbar['text'] = "Playing " + ' : ' +
os.path.basename(play)
showdetails(play)
except:
tkinter.messagebox.showerror("Error","File Doesn't Exist")
播放列表框中的项目在选择特定歌曲时以随机顺序加载,播放错误的歌曲。
我想以某种顺序加载它们,可能是按名称或大小等顺序,以便在从播放列表框中选择歌曲时播放突出显示的歌曲
许多用于列出目录内容的工具将 return 结果称为 "directory order"。这不一定是随机的,但可能会令人惊讶。
您需要做的是在使用 os.listdir()
的结果之前对这些结果进行排序。您可能会发现 sorted(os.listdir(path))
适合您的需要,或者您可能想按其他一些标准进行排序。如果您想要更具体的排序,我建议使用谷歌搜索 "python os.listdir sort by size" 或满足您特定排序要求的任何内容。
播放列表框中的项目在选择特定歌曲时以随机顺序加载,播放错误的歌曲。
尝试加载不同的文件编解码器 尝试使用代码反转加载顺序:playlist.revrse
#Suspected Problematic Code:
playlist = []
def bfolder():
global filenamepath
global directory
global index
folder = filedialog.askdirectory()
os.chdir(folder)
for filename in os.listdir(folder):
if filename.endswith(".mp3") or filename.endswith(".wav") or filename.endswith("flac") or filename.endswith(".ogg") or filename.endswith(".Mp3") or filename.endswith(".Wav") or filename.endswith(".Flac") or filename.endswith(".Ogg") or filename.endswith(".MP3") or filename.endswith(".WAV") or filename.endswith(".FLAC") or filename.endswith(".OGG"):
pg.mixer.music.queue(filename)
filename = os.path.basename(filename)
index = 0
playlist.insert(index, filename)
playlist.reverse()
playlistbox.insert('end', filename)
index +=1
updatelabel()
def updatelabel():
global index
global playlist
v.set(playlist)
#This is probably not required but here is the code used for playbutton:
def play_button():
global paused
if paused:
selected=playlistbox.curselection()
selected = int(selected[0])
play= playlist[selected]
pg.mixer.music.unpause()
statusbar['text']=os.path.basename(play),"Resumed"
paused = FALSE
else:
try:
stop_button()
time.sleep(1)
selected=playlistbox.curselection()
selected = int(selected[0])
play= playlist[selected]
pg.mixer.music.load(play)
pg.mixer.music.play()
statusbar['text'] = "Playing " + ' : ' +
os.path.basename(play)
showdetails(play)
except:
tkinter.messagebox.showerror("Error","File Doesn't Exist")
播放列表框中的项目在选择特定歌曲时以随机顺序加载,播放错误的歌曲。
我想以某种顺序加载它们,可能是按名称或大小等顺序,以便在从播放列表框中选择歌曲时播放突出显示的歌曲
许多用于列出目录内容的工具将 return 结果称为 "directory order"。这不一定是随机的,但可能会令人惊讶。
您需要做的是在使用 os.listdir()
的结果之前对这些结果进行排序。您可能会发现 sorted(os.listdir(path))
适合您的需要,或者您可能想按其他一些标准进行排序。如果您想要更具体的排序,我建议使用谷歌搜索 "python os.listdir sort by size" 或满足您特定排序要求的任何内容。