1
00:00:01,700 --> 00:00:06,830
OK, so in this video, we want to start to work on moving the slider around and then changing the position

2
00:00:06,830 --> 00:00:08,240
of the song based on that.

3
00:00:08,250 --> 00:00:14,960
So in our play time function, we can see actually I'm seeing right here where we set the slider to

4
00:00:14,960 --> 00:00:15,380
length.

5
00:00:16,580 --> 00:00:22,100
We're configuring this, we can actually just get rid of this and just paste this in or else statement

6
00:00:22,100 --> 00:00:28,400
where we're putting next time as the value, we can also we can also set the to value.

7
00:00:28,770 --> 00:00:31,130
So let's just do both of them in this function.

8
00:00:31,130 --> 00:00:31,410
Right.

9
00:00:32,340 --> 00:00:37,630
That that works and two length of song, right?

10
00:00:38,040 --> 00:00:41,430
So that means up here, we don't really need these guys.

11
00:00:41,710 --> 00:00:44,430
So, OK, not really what we want to talk about in this video.

12
00:00:44,430 --> 00:00:50,850
Just a little thing I noticed to clean up our code a little bit, but now we want to drag our slider

13
00:00:50,850 --> 00:00:55,910
around and play the song based on where the slider is at the moment.

14
00:00:55,920 --> 00:01:01,620
So let's head all the way down here to the bottom of our code, or at least the bottom of our function

15
00:01:01,620 --> 00:01:03,760
section to our slide function.

16
00:01:03,780 --> 00:01:06,420
We created several videos ago and we first set up our slider.

17
00:01:06,670 --> 00:01:08,460
Right now we just have it set to pass.

18
00:01:08,610 --> 00:01:14,490
Well, what we want to do here, when we when we move the slider, we want to play the song from whatever

19
00:01:14,490 --> 00:01:16,500
current position the slider is at.

20
00:01:16,740 --> 00:01:18,010
So how do we play a song?

21
00:01:18,030 --> 00:01:21,420
Well, let's head up to our play function and.

22
00:01:22,900 --> 00:01:23,770
Here we go.

23
00:01:24,040 --> 00:01:30,130
We know we can play songs with these four lines of code, we grab the name of the song, slap our directory

24
00:01:30,130 --> 00:01:33,090
stuff on to it, loaded into the mixer and then play it.

25
00:01:33,430 --> 00:01:34,960
So let's just copy these guys.

26
00:01:39,930 --> 00:01:45,250
So let's come down to our play or to our slide function and let's paste these, and now there is really

27
00:01:45,250 --> 00:01:47,200
just one little difference, right?

28
00:01:47,290 --> 00:01:50,380
When we play the song, we don't want to just play it.

29
00:01:50,390 --> 00:01:56,690
We want to play it from a specific position so we can set a start equal whatever we want.

30
00:01:56,730 --> 00:02:05,200
So so let's just set that equal to our song Slider so we can go song underscore slider doget.

31
00:02:05,440 --> 00:02:07,470
And these this is a function.

32
00:02:07,480 --> 00:02:09,010
So don't forget your little brackets there.

33
00:02:09,190 --> 00:02:13,000
So this will just grab whatever current position our slider is at.

34
00:02:13,000 --> 00:02:13,330
Right.

35
00:02:13,690 --> 00:02:15,520
And then play the song from that.

36
00:02:15,550 --> 00:02:19,530
Now this is going to cause us a little bit of trouble and I'll show you what that is in just a second.

37
00:02:19,540 --> 00:02:23,400
But for now, let's go ahead and save this and run it and see if that works.

38
00:02:23,890 --> 00:02:24,820
Run this guy.

39
00:02:25,980 --> 00:02:28,230
Let's add some songs you.

40
00:02:30,000 --> 00:02:30,810
Let's play one.

41
00:02:33,120 --> 00:02:34,560
Turn the volume down a bit.

42
00:02:34,830 --> 00:02:38,130
Now, if I move this forward, you can see

43
00:02:43,140 --> 00:02:43,730
it's working.

44
00:02:46,220 --> 00:02:48,410
But here's the problem I mentioned look down here.

45
00:02:48,440 --> 00:02:53,480
The last time I talked about this a couple of videos ago, if we move this around, it resets this every

46
00:02:53,480 --> 00:02:53,930
time.

47
00:02:54,620 --> 00:02:57,920
So why is it doing that?

48
00:02:58,310 --> 00:03:01,940
Well, think about what we're doing here when we move this slider.

49
00:03:06,170 --> 00:03:08,210
Let's pull up our code here.

50
00:03:08,810 --> 00:03:12,860
When we move the slider, we're playing a new instance of the song.

51
00:03:12,860 --> 00:03:15,710
We're not fast forwarding or rewinding in the song.

52
00:03:15,890 --> 00:03:19,620
Pygame doesn't do that because pygame doesn't know how long the song is.

53
00:03:19,640 --> 00:03:23,360
Remember, we had to import that mutagen thing in order to get the song going.

54
00:03:23,360 --> 00:03:27,980
So Pygame doesn't know how long the song is, therefore it doesn't know where you are in the song.

55
00:03:28,310 --> 00:03:30,920
I mean, it could tell you the current time, but.

56
00:03:32,230 --> 00:03:35,170
Based on the entire length of the song, no, not so much.

57
00:03:35,200 --> 00:03:40,870
So what we're doing here, when we replay this song, we're starting over again from zero in the current

58
00:03:40,870 --> 00:03:42,760
time or within the elapsed time.

59
00:03:42,760 --> 00:03:43,040
Right.

60
00:03:43,270 --> 00:03:45,070
So this is a bit of a problem.

61
00:03:45,070 --> 00:03:48,670
And we can fix this because we know where we are in the song.

62
00:03:49,030 --> 00:03:49,780
How do we know?

63
00:03:49,930 --> 00:03:52,750
Because the slider is wherever we we drug it.

64
00:03:53,020 --> 00:03:58,840
And since the slider is the length of the song, wherever the slider is, we know where it is in relationship

65
00:03:58,840 --> 00:03:59,940
to the length of the song.

66
00:04:00,310 --> 00:04:04,450
So we could just output into the status bar our current position of our slider.

67
00:04:04,840 --> 00:04:05,170
Right.

68
00:04:05,170 --> 00:04:07,330
And that will be the the elapsed time.

69
00:04:07,330 --> 00:04:07,640
Right.

70
00:04:07,660 --> 00:04:10,200
So that's one way we can fix that and that's what we're going to do.

71
00:04:10,210 --> 00:04:11,450
So I'll see.

72
00:04:11,530 --> 00:04:13,040
This video is getting a little bit long.

73
00:04:13,060 --> 00:04:16,000
Let's go ahead and stop this one and we'll pick this up in the next video.
