查找mp3文件的长度 [英] Finding the length of an mp3 file
本文介绍了查找mp3文件的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有代码:
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)
但是它所做的就是不停地浏览所有歌曲.我以为如果可以找到当前正在播放的歌曲的长度,则可以使用时间"模块在具有(睡眠)属性的歌曲播放完后继续播放.但是,我找不到如何在Windows上获得歌曲的长度.有人知道我的问题的解决方案吗?
but all it does is go through all of the songs without stopping. I thought if I could find the length of the song that is currently playing, I could use the "time" module to keep going after the song is done with the (sleep) attribute. However, I couldn't find how to get the length of the song on windows. Does anyone know a solution to my probleme?
推荐答案
You can use mutagen to get the length of the song (see the tutorial):
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
print(audio.info.length)
这篇关于查找mp3文件的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文