Finding the length of an mp3 file

前端 未结 5 1362
孤城傲影
孤城傲影 2020-12-09 09:02

So i have the code:

import glob,os
import random


path = \'C:\\\\Music\\\\\'
aw=[]
for infile in glob.glob( os.path.join(path,\'*.mp3\') ):
    libr = infil         


        
5条回答
  •  暖寄归人
    2020-12-09 09:48

    Maybe do the playing also within Python, i.e. don't use os.startfile, use some Python library to play the file.

    I have recently written such a library/module, the musicplayer module (on PyPI). Here is a simple demo player which you can easily extend for your shuffle code.

    Just do easy_install musicplayer. Then, here is some example code to get the length:

    class Song:
        def __init__(self, fn):
            self.f = open(fn)
        def readPacket(self, bufSize):
            return self.f.read(bufSize)
        def seekRaw(self, offset, whence):
            self.f.seek(offset, whence)
            return self.f.tell()
    
    import musicplayer as mp
    
    songLenViaMetadata = mp.getMetadata(Song(filename)).get("duration", None)
    songLenViaAnalyzing = mp.calcReplayGain(Song(filename))[0]
    

提交回复
热议问题