如何使用Python在os.startfile中播放音频列表?

2024-10-05 14:29:57 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用Python在os.startfile中播放音频列表

我的代码:

import os

music_dir = "C:\\Users\\JACKSON KASI\\Music"
songs = os.listdir(music_dir)
print(songs)

for i in songs:
    os.startfile(os.path.join(music_dir,i))

下一个音频文件应在第一个音频文件完全运行后运行。 但我的代码是快速播放所有音频。这并不完美。 请帮帮我。

您是否可以使用pygame(或)pythonvlc来解决这个问题


Tags: 代码import列表osdirmusic音频users
2条回答

os.startfile只是在后台异步启动文件。每the docs

startfile() returns as soon as the associated application is launched. There is no option to wait for the application to close, and no way to retrieve the application’s exit status.

基本上,你不能将它用于你的目的,因为没有办法知道它何时完成

播放媒体文件有很多很多演练;请在web上搜索解决方案(从头开始提供完整的解决方案有些超出StackOverflow问题的范围)

random = os.startfile(os.path.join(music_dir , songs[1])

这会奏效的

相关问题 更多 >