使用 Python 在 Windows Media Player 中排队并播放 .mp3 文件夹
是否可以在 Windows Media Player 中播放文件夹中的所有 .mp3?
我使用的是 Python 3.2,到目前为止,我有代码可以返回音乐文件夹中随机专辑的绝对位置。 我想以某种方式打开 WMP 并播放该文件夹中的音乐
有什么建议吗?
作为参考,这是我的代码:
import random
import os
path = ["Q:\\#User\\Music\\", "Q:\\#user\\What CDs\\"]
print("You shall play " + random.sample(list(filter(lambda f: len([i for i in f if i in "."]) == 0, sum(map(lambda d: list(map(lambda e: d + "\\" + e,os.listdir(d))),list(filter(lambda c: len([i for i in c if i in "."]) == 0, sum(map(lambda a: list(map(lambda b: a + b ,os.listdir(a))), path), [])))), []) )), 1)[0])
input()
是的,理想情况下这不会全部都在一行中。我正在学习如何使用 map
和 lambda
并认为我会挑战自己。 我现在想更进一步,播放随机专辑。
谢谢!
Is it possible to play all the .mp3's within a folder in windows media player?
I am using Python 3.2, and so far I have code that returns the absolute location of a random album in my music folder.
I would like to take that string and somehow open WMP and play the music within that folder
Any suggestions?
For reference, here is my code:
import random
import os
path = ["Q:\\#User\\Music\\", "Q:\\#user\\What CDs\\"]
print("You shall play " + random.sample(list(filter(lambda f: len([i for i in f if i in "."]) == 0, sum(map(lambda d: list(map(lambda e: d + "\\" + e,os.listdir(d))),list(filter(lambda c: len([i for i in c if i in "."]) == 0, sum(map(lambda a: list(map(lambda b: a + b ,os.listdir(a))), path), [])))), []) )), 1)[0])
input()
And yes, ideally that wouldn't all be in one line. I was learning how to use map
and lambda
and thought I'd challenge myself.
I'd now like to take this one step further, and play the random album.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,有趣的想法。
我可能会即时创建一个 .m3u 文件,然后将其作为命令行参数传递给 WMP(根据 WMP 命令行 当然是可行的)。
.m3u 文件只是一个文本文件。以下是 Tool 专辑 Undertow 的 .m3u 示例:
祝你好运!
PS - 您可以通过导入 os 模块并使用 os.system("YOUR DOS COMMAND") 来调用命令行参数
哦,还有 m3u 文件中使用的格式:
如果没说清楚的话。
Hmmmm, interesting idea.
I would probably create a .m3u file on the fly and then pass it to WMP as a command line argument (which, according to WMP Command Line is certainly doable).
A .m3u file is simply a text file. Here is an example .m3u for the Tool album Undertow:
Good luck!
PS - You can invoke the command line argument by importing the
os
module and usingos.system("YOUR DOS COMMAND")
Oh, and the format used in an m3u file:
If it wasn't clear.