OK, in this video, we're going to find the total length of a song, so the time length of a song and
last video, we got the current position of a song in this video.
We want to get the whole song length.
So if we have a song, how long is that song?
Right.
Actually, pygame doesn't have any sort of mechanism to do this.
It does if you're working with, like, wav files, but not for MP three files.
So we have to actually use a third party thing in order to do that.
So we need to pip install that now.
So head over to your terminal, make sure you're in your C and B three directory and have your virtual
environment turned on.
And let's go pip install mutagen.
It's just mutty a g e n mutagen.
And this thing, you know, it will find the song length of an MP three player and does some other MP
three stuff, but we don't really care about that.
So, OK, that's now PIP installed.
Now we need to add it to our code so.
Let's come up here to the top of our thing and let's import this guy so we can go from mutagen dot MPLX
three, import MPLX three, and this MPLX three here is capitalized.
This one is not so OK.
Now we can use a mutagen inside of our app.
So let's come down to our play time function and let's make some space here and let's find a current
song length.
Right.
So let's create a variable call it song underscore mutty for mutagen and we want to call an MP three
instance.
And what do we want to look up?
Well, we want to look up song.
But what is song.
Well.
We've done this before in the past in our play function, in fact, we could come down to our play function
and just copy these two things here, right?
So we get the song that's the currently active one in the playlist, and then we can slap in these things,
so let's just copy this, bring this back up here.
And paste them in.
OK, so here we can sort of create an MP three instance, a mutagen instance of this song right now,
we're actually going to need this somewhere else.
So let's make this a global and let's call this song underscore length.
Now to get the song, the Let's Go song underscore length equals this song, The Mud, right?
Info that links.
And that will return the length of the song.
So what is this returning?
Well, let's come down to the bottom of our code again and grab this.
My label is use this for testing purposes and it's headed back up to our play time thing.
And let's just pop this on the screen and config this and what do we want to do?
We want to set the text equal to song underscore length.
So let's go ahead and copy that or let's go ahead and save this and run it.
And let's add a bunch of songs.
And you can see it's one hundred point eighty six to whatever, right?
So that's, again, all not that super useful.
So let's convert this again, like we converted this one into time so we can say, you know, one hundred
seconds.
What is that?
Well, that's a minute.
And 40 like, you don't have to do that math.
So let's convert this to time so we can do that.
So let's go convert to time format.
And let's go let's create let's create a new variable called Converted Underscore Song Length.
And let's set that equal to how we can come up here and just copy this whole thing.
And paste it in here, because it's the same thing we're doing as we did earlier, but instead of.
Doing it on current time, we're going to do it on song length.
You just copy this and paste this in.
OK, so now instead of outputting song length the label, let's output converted song.
Let's save this and run it.
See what this looks like.
Oh, it's add about songs you.
Let's play one.
So it's two minutes and 19 seconds, right, that looks much that's much easier to read, right?
This one is two minutes and 30 seconds.
This one is two minutes in two seconds.
I mean, if you do so, very cool now we have this so we've got this here, we don't want to put it
in this label, let's put it in our status bar so we can do that.
So instead of this label, let's just get rid of that and let's just add this variable to our status
bar down here so we already have the time elapsed.
Let's go of and then put two more brackets in inside of here.
Put that converted song length.
So it's going to say this and run it.
See what this looks like.
So we can add many songs.
Play one, so it's one second of a minute, forty seven.
One second of two minutes and 30 seconds, and this is shoved right up against there, so maybe let's
put a couple of spaces there.
We knew that we could just.
Pop that like that, maybe to save this and run it again.
See, at some songs you.
That's off the side of that a little bit.
There's some space in there, and I think that looks better.
So, OK, we are coming right along now.
There's a couple of little things that are weird.
When we click this stop button, this gets reset to that.
So we might want to fix that.
And maybe some other little things like that will start to look at those in the next video.