繁体   English   中英

如何让我的代码随机播放多首歌曲?

[英]How do I make my code play more than one song randomly?

我对此有点陌生,我需要一些帮助; 我有这段代码,它基本上是从您所在的当前目录中播放一首歌曲,我想知道您是否可以以某种方式让它随机播放多首歌曲而不会重复播放,直到列表结束。 谢谢

    import random,os,sys

folder=os.listdir(os.getcwd())

file=random.choice(folder)
ext3=['.mp3']
print('First random pick: '+file)

while file[-4:] not in ext3 :
       
       print('Not an MP3 file  : '+file)
       file=random.choice(folder)
else:
       os.startfile(file)
       print('Song name: '+file)



##os.startfile(random.choice(folder))
import random, os, sys

folder = os.listdir(os.getcwd())

mp3s = [file for file in folder if file.endswith('.mp3')]
queue = random.shuffle(mp3s)
for file in queue:
    print('Song name:', file)
    os.startfile(file)

当你第一次运行程序时,在目录中创建一个当前歌曲的数组。 然后,从数组中随机播放一首歌曲。 开始播放歌曲后,从数组中弹出歌曲,以便列表仅包含未播放的歌曲。 使用前一种逻辑遍历数组以遍历数组,直到没有歌曲剩余。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM