Progressbar to show amount of music played
<p>Suppose I use <code>mp3play</code> module to play mp3 files, and using <code>ttk.Progressbar</code>, I want to show the amount(duration) of music played. Is there any code to achieve it?  </p>

<p>I also want a timer a to show the duration of music played.</p>

<pre><code>import ttk
import mp3play
self.music = mp3play.load('filename')
self.fr=ttk.Frame()
self.fr.pack(expand=True, fill=BOTH, side=TOP)
self.seek=ttk.Progressbar(self.fr, orient='horizontal', mode='determinate', length=500)
self.seek.place(x=50, y=325)
self.seek.start()
</code></pre>

<p>Looking at the code of <code>mp3play</code>module, <code>mp3play.load()</code> returns an <code>AudioClip</code> object. This object has the methods <code>seconds()</code> and <code>milliseconds()</code> that provide the length of the clip in seconds or milliseconds respectively.</p>

<p>You can save the time when you started playing and compare it to the current time and the total length of the clip to determine the status of the progressbar.</p>

<pre><code># assuming time would me measured in milliseconds
start = time()
while playing:
    # progress measured in percentages
    progress = 100 * (time() - start)/ clip.milliseconds()
</code></pre>

python python-2.7 tkinter