1
00:00:01,720 --> 00:00:05,710
OK, so we've got our volume slider here and it's looking pretty good, but it doesn't actually do anything

2
00:00:05,710 --> 00:00:07,240
when we slide this thing around.

3
00:00:07,250 --> 00:00:09,700
So let's work on that in this video.

4
00:00:09,700 --> 00:00:15,310
So I'll clear the screen here and back over to our coat and inside of our volume.

5
00:00:15,310 --> 00:00:16,860
Slider, where are we to find it?

6
00:00:17,260 --> 00:00:23,970
Let's give this a command, equal volume and now we need to create that function.

7
00:00:24,370 --> 00:00:26,740
So head back up to our.

8
00:00:28,520 --> 00:00:31,330
Function section here, and I'm just going to put this at the bottom.

9
00:00:33,330 --> 00:00:39,510
So let's go create volume function and let's define this.

10
00:00:41,260 --> 00:00:45,190
Now, this one's a little different, we have to actually put something here because whenever we move

11
00:00:45,190 --> 00:00:51,400
our slider, it's passing whatever the position argument, the position number is into the function

12
00:00:51,400 --> 00:00:52,090
that we call.

13
00:00:52,270 --> 00:00:56,800
And when we do that, this function needs to be waiting to sort of listening for that number.

14
00:00:56,980 --> 00:00:59,840
And so we're going to assign that number to the variable X.

15
00:00:59,860 --> 00:01:04,570
Now, we're not actually going to use this variable, but still the function knows it's supposed to

16
00:01:04,570 --> 00:01:05,620
be listening for that.

17
00:01:05,650 --> 00:01:08,410
So if we don't put that little X there, we're going to get an error.

18
00:01:08,410 --> 00:01:10,400
So we'll just leave that there for now.

19
00:01:10,420 --> 00:01:14,140
So let's take a look and see because we haven't really talked about sliders.

20
00:01:14,140 --> 00:01:20,050
Let's come down here and grab our temporary label thing and let's just come up here and let's just see

21
00:01:20,050 --> 00:01:22,630
what the slider does when we move it around.

22
00:01:22,630 --> 00:01:27,100
So let's let's my label config.

23
00:01:28,850 --> 00:01:34,860
And let's give this a text equal, whatever the name of our slider is, which is volume slider.

24
00:01:35,180 --> 00:01:42,230
Now we can get the current position of the slider by calling volume underscore slider doget and then

25
00:01:42,230 --> 00:01:45,620
put your little function thing so and we could just output this onto that text.

26
00:01:45,620 --> 00:01:50,120
So let's go and save this just to see what the heck this is actually doing, because this is kind of

27
00:01:50,120 --> 00:01:50,630
interesting.

28
00:01:52,510 --> 00:01:59,110
So we've got our slider and we move it and we could see it's a it's a decimal, it's a float, so point

29
00:01:59,110 --> 00:02:01,990
five, six, six, it starts at zero.

30
00:02:01,990 --> 00:02:05,710
And at the very top here, the very bottom, I should say, is at one.

31
00:02:06,130 --> 00:02:06,610
So.

32
00:02:07,650 --> 00:02:14,370
One is the high, obviously, zero is the low, why is it zero and one because when we set this thing

33
00:02:14,370 --> 00:02:17,040
up, we set the from.

34
00:02:19,340 --> 00:02:25,490
To zero and the two to one, if we set this to one hundred, the bottom position would be one hundred,

35
00:02:25,490 --> 00:02:25,730
right.

36
00:02:25,730 --> 00:02:31,310
But we want it just from zero to one because I mentioned PI games, volume control's returns, numbers

37
00:02:31,310 --> 00:02:32,570
from zero to one.

38
00:02:32,760 --> 00:02:34,400
So that's what we want it to be.

39
00:02:34,430 --> 00:02:39,680
So you might wonder why there's an underscore here under from from is a python key word.

40
00:02:39,680 --> 00:02:43,610
So we can't use from encounter but we can use from underscore.

41
00:02:43,610 --> 00:02:45,140
So that's sort of what they do.

42
00:02:45,140 --> 00:02:46,280
It's just the convention.

43
00:02:46,280 --> 00:02:51,860
So, OK, we're getting a float now up here between zero and one.

44
00:02:51,860 --> 00:02:58,340
So zero point something, zero point one zero point two and zero is obviously no sound.

45
00:02:58,340 --> 00:03:01,880
And one is obviously the most loud sound there can be.

46
00:03:02,090 --> 00:03:02,480
Right.

47
00:03:02,630 --> 00:03:06,110
And before we move on, I want to show you one other thing.

48
00:03:06,300 --> 00:03:07,760
Let's run this thing again real quick.

49
00:03:08,780 --> 00:03:14,510
You know, it starts at zero, I think I want it to start at one because we want the volume to start

50
00:03:14,690 --> 00:03:15,250
loud.

51
00:03:15,260 --> 00:03:19,550
We don't want the volume to start, you know, at zero zero is nothing.

52
00:03:19,550 --> 00:03:20,780
You can't hear zero at all.

53
00:03:20,960 --> 00:03:23,840
Or if you want, you could put it at halfway point five or whatever.

54
00:03:23,840 --> 00:03:27,130
But I'm just going to blast it out at one the highest volume to begin with.

55
00:03:27,140 --> 00:03:27,850
So how do we do that?

56
00:03:27,860 --> 00:03:34,160
Well, we do that really simply in our volume slider where we defined it here, this volume frame,

57
00:03:34,160 --> 00:03:39,230
we just come here and we could just set a value and almost set the value equal to one.

58
00:03:39,240 --> 00:03:40,880
So now if we save this and run it.

59
00:03:44,400 --> 00:03:48,050
You can see now it starts out down here, so that's better.

60
00:03:48,450 --> 00:03:54,270
So, OK, now the only thing left to do is have this thing actually change the volume right here so

61
00:03:54,270 --> 00:03:56,060
we can get rid of this label thing.

62
00:03:56,070 --> 00:03:58,920
We don't really need to know what the volume is at any given time.

63
00:03:59,280 --> 00:04:01,560
Now we need to actually write the code to change the volume.

64
00:04:01,570 --> 00:04:02,370
So how do we do that?

65
00:04:02,640 --> 00:04:03,930
This is actually very, very easy.

66
00:04:03,960 --> 00:04:05,820
All we have to do is go pygame.

67
00:04:07,080 --> 00:04:15,830
That Mixu music dot said underscore volume, and this is a function and what do we want to send it to?

68
00:04:15,840 --> 00:04:18,600
We want to send it to whatever the slider is right now.

69
00:04:18,600 --> 00:04:25,020
And we know from our label we just deleted that we can get the current slider position by calling volumes,

70
00:04:25,020 --> 00:04:29,190
underscore slider and get it's there we go.

71
00:04:29,760 --> 00:04:33,030
And then passing in the little function brackets and that's it.

72
00:04:33,030 --> 00:04:35,850
So we can save this now and let's try this out.

73
00:04:35,850 --> 00:04:37,320
So let's run this guy.

74
00:04:39,150 --> 00:04:41,610
Hold on over, let's add a bunch of songs.

75
00:04:43,050 --> 00:04:43,950
And let's play one.

76
00:04:46,070 --> 00:04:47,830
How to move the volume down?

77
00:04:52,500 --> 00:04:55,520
Can you can I tell and then it's gone.

78
00:04:55,540 --> 00:04:56,320
So let's do a.
