1
00:00:01,790 --> 00:00:03,840
OK, so we've installed an imported pygame.

2
00:00:03,980 --> 00:00:08,840
Now we want to start to use it, so let's come down here to our buttons and remember when we defined

3
00:00:08,840 --> 00:00:12,050
all these buttons and put them up on the screen, here's our play button.

4
00:00:12,260 --> 00:00:16,760
And if we go to the end of this thing, we could see it's got our image or border with.

5
00:00:16,910 --> 00:00:18,440
Now, we want to give this a command.

6
00:00:19,280 --> 00:00:22,670
And I'm going to call this play now whenever we want to click on a button.

7
00:00:22,670 --> 00:00:26,810
And we wanted to do something, we use these commands and this command we're calling play.

8
00:00:26,810 --> 00:00:29,240
So I'm going to copy this and then come up to the top.

9
00:00:30,160 --> 00:00:35,440
Of our app here and just kind of scroll down here, we've got all of our other functions that we've

10
00:00:35,440 --> 00:00:41,870
created so far and it's just come down here and let's go create play function.

11
00:00:42,460 --> 00:00:48,330
So we want to define this call it play now in order to actually play a song.

12
00:00:48,340 --> 00:00:49,540
It's pretty simple.

13
00:00:49,970 --> 00:00:53,080
Let's look up here when we added a song.

14
00:00:53,110 --> 00:00:57,880
Remember, we stripped out these things from the name so and are placing the first thing we want to

15
00:00:57,880 --> 00:01:03,640
do is we want to determine what song we want to play, what we want to play, the one that's been clicked

16
00:01:03,640 --> 00:01:05,560
in our playlist, the one that's active.

17
00:01:05,740 --> 00:01:06,050
Right.

18
00:01:06,080 --> 00:01:08,230
So let's create a variable called song.

19
00:01:09,130 --> 00:01:15,070
And remember, our playlist is called Playlist Box so we can go grab the playlist box.

20
00:01:16,470 --> 00:01:18,210
Get and what do we want to get?

21
00:01:18,240 --> 00:01:25,230
We want to get the active song right now, let's come down here and remember we created this temporary

22
00:01:25,230 --> 00:01:28,740
label called My Label, and it text has nothing.

23
00:01:28,740 --> 00:01:30,840
Let's no output to the screen.

24
00:01:33,240 --> 00:01:39,870
What our song is that we've just selected, so let's go my label that config, and set the text equal

25
00:01:39,870 --> 00:01:43,290
to song just to see what happens when we click this button.

26
00:01:43,620 --> 00:01:48,610
Let's save this head back over to our terminal and let's run Python player up.

27
00:01:50,280 --> 00:01:52,110
So let's add a bunch of songs.

28
00:01:53,900 --> 00:01:59,630
And let's click on one, and now when we click play, you could see it says no when sad majesty.

29
00:01:59,640 --> 00:02:03,370
So it's it's just returning whatever is in this box, right?

30
00:02:03,380 --> 00:02:04,970
So that's not great.

31
00:02:04,970 --> 00:02:09,140
We can't look up and play that song with just this stuff.

32
00:02:09,380 --> 00:02:14,030
We need that other stuff from earlier and by the other stuff.

33
00:02:14,030 --> 00:02:17,510
I mean, let's see all of this stuff.

34
00:02:17,510 --> 00:02:21,620
So we sort of deconstructed this to put it in the playlist.

35
00:02:21,620 --> 00:02:28,040
Now we need to reconstruct it and add these things back in so that we can then play the song.

36
00:02:28,040 --> 00:02:29,150
So let's do that.

37
00:02:30,750 --> 00:02:38,700
So let's go song equals and I could do an F string, this is just a python F string that allows us to

38
00:02:38,700 --> 00:02:40,830
take things and kind of smush them together.

39
00:02:40,830 --> 00:02:41,810
So let's go.

40
00:02:41,820 --> 00:02:45,690
We want capital C Colon for display space.

41
00:02:45,690 --> 00:02:47,850
We want to add in our directory structure.

42
00:02:47,850 --> 00:02:55,590
So we're in the directory MP three and we want audio because all of our songs are saved in that audio

43
00:02:55,590 --> 00:02:56,250
directory.

44
00:02:57,600 --> 00:02:59,040
And then what do we want?

45
00:02:59,080 --> 00:03:04,560
Also, we want to put these curly brackets and then put song, which is just the name of the song from

46
00:03:04,560 --> 00:03:05,370
the playlist.

47
00:03:05,910 --> 00:03:10,920
And then we also want to put DOT MP three at the end of it.

48
00:03:10,920 --> 00:03:18,000
So let's go and save this now and run it and then output this song just to see what it is now that we've

49
00:03:18,000 --> 00:03:18,940
changed it a little.

50
00:03:18,960 --> 00:03:19,270
Right.

51
00:03:19,320 --> 00:03:20,430
So let's run this guy.

52
00:03:20,790 --> 00:03:22,440
Well let's over add a bunch of songs.

53
00:03:22,590 --> 00:03:26,820
You open analysts' click hiking for instance.

54
00:03:27,270 --> 00:03:33,180
We click this now it's C colon and B three slash audio slash hiking dot MP three.

55
00:03:33,180 --> 00:03:36,840
So now that whole string is what we need.

56
00:03:36,840 --> 00:03:41,250
That's going to allow us to now look up and play a specific song.

57
00:03:41,250 --> 00:03:44,880
We know exactly on our computer where it's sitting and we can now play it.

58
00:03:45,030 --> 00:03:48,210
So let's close this and in order to actually play a song.

59
00:03:48,840 --> 00:03:53,280
So let's comment this reconstruct.

60
00:03:54,840 --> 00:03:58,380
Song with directory.

61
00:03:59,620 --> 00:04:02,810
Structure stuff, right?

62
00:04:03,790 --> 00:04:11,080
And then we actually don't need this, so we can take that label thing off and now let's play a song

63
00:04:11,080 --> 00:04:13,390
with pygame, Mixu.

64
00:04:14,940 --> 00:04:21,780
So to do that, we call pygame mixer, dot music, dot lod.

65
00:04:23,870 --> 00:04:25,170
And then what do we want to load?

66
00:04:25,190 --> 00:04:31,010
We want to load in our song, which is this thing right here, which is this newly reconstructed sort

67
00:04:31,010 --> 00:04:32,180
of string of stuff.

68
00:04:32,180 --> 00:04:32,450
Right.

69
00:04:32,720 --> 00:04:35,110
So we always this is always a two step process.

70
00:04:35,120 --> 00:04:37,100
We load the song and then we play the song.

71
00:04:37,100 --> 00:04:38,630
So to play it.

72
00:04:39,760 --> 00:04:49,510
I should probably put load song with Pygame Mixer and then here, let's play a song with Pygame Mixer,

73
00:04:49,640 --> 00:04:52,120
so we just go pygame that mixer.

74
00:04:53,980 --> 00:04:59,060
That music does not play and we can pass some variables here.

75
00:04:59,080 --> 00:05:03,040
I'm going to call loops equal zero and this is a lower L.

76
00:05:03,040 --> 00:05:07,120
I know it kind of looks like a capital L sublime does that drives me crazy, but that's a lowercase

77
00:05:07,120 --> 00:05:10,990
L and this is just basically saying play the song just once.

78
00:05:11,110 --> 00:05:15,850
If we want it to loop and just keep playing you, you can have it play five times.

79
00:05:15,850 --> 00:05:17,430
You could just put loops equal five.

80
00:05:17,650 --> 00:05:20,830
We just wanted to play once and so loops equals zero.

81
00:05:20,830 --> 00:05:22,330
So let's go and save this and run it.

82
00:05:23,980 --> 00:05:27,070
So pull this over, add some songs.

83
00:05:28,930 --> 00:05:31,210
Let's play hiking our.

84
00:05:33,310 --> 00:05:33,870
Seems to work.

85
00:05:35,730 --> 00:05:39,210
Look, another one it plays.

86
00:05:43,820 --> 00:05:44,160
Right.

87
00:05:46,070 --> 00:05:51,140
Very cool, so that's how to play a song now none of these other buttons work, and I think we're going

88
00:05:51,140 --> 00:05:52,150
to need to fix those.

89
00:05:52,160 --> 00:05:55,190
I think we'll do the stop button next, and that'll be in the next video.
