所以我有代码:
import glob,os
import random
path = 'C:\\Music\\'
aw=[]
for infile in glob.glob( os.path.join(path,'*.mp3') ):
libr = infile.split('Downloaded',1)
aw.append(infile)
aww = -1
while 1:
aww += 1
print len(aw),aww
random.shuffle(aw)
awww = aw[aww]
os.startfile(awww)
Run Code Online (Sandbox Code Playgroud)
但它所做的就是不停地浏览所有歌曲.我想如果我能找到当前正在播放的歌曲的长度,我可以使用"时间"模块继续歌曲完成后使用(sleep)属性.但是,我找不到如何在Windows上获取歌曲的长度.有谁知道我的问题的解决方案?
Gre*_*egg 42
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
print(audio.info.length)
Run Code Online (Sandbox Code Playgroud)
jun*_*ist 10
的较新版本python-ffmpeg有一个包装函数ffprobe。获取持续时间的示例如下:
import ffmpeg
print(ffmpeg.probe('in.mp4')['format']['duration'])
Run Code Online (Sandbox Code Playgroud)
发现于: https: //github.com/kkroening/ffmpeg-python/issues/57#issuecomment-361039924
您可以使用FFMPEG库:
args=("ffprobe","-show_entries", "format=duration","-i",filename)
popen = subprocess.Popen(args, stdout = subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
Run Code Online (Sandbox Code Playgroud)
输出将是:
[FORMAT]
duration=228.200515
[/FORMAT]
Run Code Online (Sandbox Code Playgroud)
如果你喜欢的话,你也可以使用 eyes3 来获得这个:
import eyed3
duration = eyed3.load('path_to_your_file.mp3').info.time_secs
Run Code Online (Sandbox Code Playgroud)
但请注意,这使用采样来确定轨道的长度。因此,如果使用可变比特率,样本可能无法代表整体,并且估计值可能会有很大偏差(我在法庭录音中看到这些估计值偏差超过 30%)。
我不确定这比其他选项差多少,但如果您有可变比特率,请记住这一点。
| 归档时间: |
|
| 查看次数: |
22044 次 |
| 最近记录: |