使用 Python 在 Windows Media Player 中排队并播放 .mp3 文件夹

发布于 2025-01-02 12:32:35 字数 720 浏览 1 评论 0原文

是否可以在 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()

是的,理想情况下这不会全部都在一行中。我正在学习如何使用 maplambda 并认为我会挑战自己。 我现在想更进一步,播放随机专辑。

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坦然微笑 2025-01-09 12:32:35

嗯,有趣的想法。

我可能会即时创建一个 .m3u 文件,然后将其作为命令行参数传递给 WMP(根据 WMP 命令行 当然是可行的)。

.m3u 文件只是一个文本文件。以下是 Tool 专辑 Undertow 的 .m3u 示例:

#EXTM3U
#EXTINF:295,Tool - Intolerance
01 - Intolerance.mp3
#EXTINF:296,Tool - Prison Sex
02 - Prison Sex.mp3
#EXTINF:307,Tool - Sober
03 - Sober.mp3
#EXTINF:434,Tool - Bottom
04 - Bottom.mp3
#EXTINF:330,Tool - Crawl Away
05 - Crawl Away.mp3
#EXTINF:332,Tool - Swamp Song
06 - Swamp Song.mp3
#EXTINF:322,Tool - Undertow
07 - Undertow.mp3
#EXTINF:363,Tool - 4°
08 - 4°.mp3
#EXTINF:466,Tool - Flood
09 - Flood.mp3
#EXTINF:947,Tool - Disgustipated
69 - Disgustipated.mp3

祝你好运!

PS - 您可以通过导入 os 模块并使用 os.system("YOUR DOS COMMAND") 来调用命令行参数

哦,还有 m3u 文件中使用的格式:

#EXTINF:<song-time-in-seconds>, <Artist> - <Song>
<Track_Num> - <File name>

如果没说清楚的话。

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:

#EXTM3U
#EXTINF:295,Tool - Intolerance
01 - Intolerance.mp3
#EXTINF:296,Tool - Prison Sex
02 - Prison Sex.mp3
#EXTINF:307,Tool - Sober
03 - Sober.mp3
#EXTINF:434,Tool - Bottom
04 - Bottom.mp3
#EXTINF:330,Tool - Crawl Away
05 - Crawl Away.mp3
#EXTINF:332,Tool - Swamp Song
06 - Swamp Song.mp3
#EXTINF:322,Tool - Undertow
07 - Undertow.mp3
#EXTINF:363,Tool - 4°
08 - 4°.mp3
#EXTINF:466,Tool - Flood
09 - Flood.mp3
#EXTINF:947,Tool - Disgustipated
69 - Disgustipated.mp3

Good luck!

PS - You can invoke the command line argument by importing the os module and using os.system("YOUR DOS COMMAND")

Oh, and the format used in an m3u file:

#EXTINF:<song-time-in-seconds>, <Artist> - <Song>
<Track_Num> - <File name>

If it wasn't clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文