1 00:00:00,600 --> 00:00:01,490 Hello and welcome. 2 00:00:01,530 --> 00:00:10,180 In this lecture we are going to add the code to make the music player work. 3 00:00:10,630 --> 00:00:11,520 All right. 4 00:00:11,550 --> 00:00:19,770 First thing I want to do a sum generate an event handler for each of these buttons. 5 00:00:19,950 --> 00:00:28,530 Basically an event handler is used to response to an event an event basically something an action that 6 00:00:28,620 --> 00:00:30,720 is performed on an application. 7 00:00:30,720 --> 00:00:35,760 When the application is running for example a click is an event. 8 00:00:35,760 --> 00:00:42,880 So the correspondent corresponding event handler would be a click event handler. 9 00:00:42,960 --> 00:00:44,640 So let's start with the brass button. 10 00:00:44,680 --> 00:00:46,210 So double click on that. 11 00:00:46,380 --> 00:00:54,750 And that would generate a stop of the code is top meaning it just generates an empty method or empty 12 00:00:54,750 --> 00:00:55,410 function. 13 00:00:55,410 --> 00:00:59,840 So we have to write the code in between these curly braces. 14 00:00:59,850 --> 00:01:06,210 You can see them the cursor is flashing waiting for us to start writing the code. 15 00:01:06,210 --> 00:01:20,640 What I am going to do here I'm going to use an if statement just to check or to check the dialog box 16 00:01:20,970 --> 00:01:24,040 to see if the file has been open. 17 00:01:24,060 --> 00:01:32,130 When you click on the browse button so would type in if we just to the intelligence skip not the guide. 18 00:01:32,540 --> 00:01:41,260 So in the if statement we added an open file dialog box so I'm gonna pass that into the if statement. 19 00:01:41,260 --> 00:01:45,400 So it's a lowercase o. 20 00:01:45,600 --> 00:01:47,750 So this is the look. 21 00:01:47,760 --> 00:01:50,170 This will now become the ope. 22 00:01:50,220 --> 00:01:55,300 This is the open file a box we added earlier on to our form. 23 00:01:55,470 --> 00:01:56,850 So we'll need to do here. 24 00:01:56,880 --> 00:02:04,740 We need to attach a method to it that will use to display the box the open dialogue. 25 00:02:04,740 --> 00:02:10,880 So if you press dot or period it gives you a list of methods you can use if you type in show. 26 00:02:11,100 --> 00:02:14,130 It would show you this show dialog box. 27 00:02:14,160 --> 00:02:19,890 So this show dialog is a method every method must be enclosed in parentheses. 28 00:02:20,520 --> 00:02:25,380 So it tells you this this is a sure dialog box. 29 00:02:25,380 --> 00:02:29,880 So what we need to do is complaining at the moment because I've not finished writing the code. 30 00:02:29,880 --> 00:02:36,630 So what I need to do I need to set a need to way for the if statement to check something. 31 00:02:36,660 --> 00:02:40,470 So to check or evaluate you do double equals two. 32 00:02:40,600 --> 00:02:43,420 And I wanted to check the dialog there. 33 00:02:43,600 --> 00:02:46,810 So this is dialogue results. 34 00:02:47,130 --> 00:02:51,820 And I want to attach a value to it and you can attach and poke. 35 00:02:52,620 --> 00:02:59,730 So if you're not sure what any parts of the code does just place your mouse over it and the idea will 36 00:02:59,880 --> 00:03:05,910 illustrate or tell you give you a tool tip guide us to what that code does it tells you this is a method 37 00:03:06,480 --> 00:03:10,770 a wrongs a common dialog box with a default owner. 38 00:03:10,790 --> 00:03:11,300 OK. 39 00:03:11,440 --> 00:03:21,120 That tells you that that is an open file open file dialog for form one form one is the is the form that 40 00:03:21,120 --> 00:03:24,120 this dialogue is attached to and the. 41 00:03:24,120 --> 00:03:30,370 Okay here the dialog box returns value is okay. 42 00:03:30,590 --> 00:03:33,920 Okay tells you usually sent from a button labeled okay. 43 00:03:34,600 --> 00:03:39,660 Okay in this instance is the button is not a hook not code okay by gives you a guide. 44 00:03:39,660 --> 00:03:51,360 What that what is this method does not is I've got this red squiggly line here because it's complaining 45 00:03:51,360 --> 00:03:56,350 that I have not finished the code telling me that this is an invalid expression. 46 00:03:56,460 --> 00:04:01,680 So it's telling me you know it's expecting because if the code is finished I should put a semicolon 47 00:04:01,680 --> 00:04:03,360 there but it's not finished. 48 00:04:03,470 --> 00:04:10,680 Is an if statement when you are using the if statement you get to you have to specify the code that 49 00:04:10,680 --> 00:04:14,080 will run for that if statement. 50 00:04:14,250 --> 00:04:23,400 So to do that I need to specify blank curly braces just expand that in between the curly braces is where 51 00:04:23,400 --> 00:04:30,270 I will write the code that will be activated in response to this if statement. 52 00:04:30,810 --> 00:04:34,910 So what I'm going to do I'm going to reference the text box. 53 00:04:34,920 --> 00:04:39,460 We added a text box earlier whether the text box 1. 54 00:04:40,050 --> 00:04:50,260 So dot text I'm going to attach a text property to it. 55 00:04:50,980 --> 00:04:51,940 All right. 56 00:04:51,940 --> 00:05:02,540 And I'm gonna set that value to equals to the open dialogue. 57 00:05:03,040 --> 00:05:10,470 I'm going to set it to equals to that and I'm going to attach a file name to that. 58 00:05:10,470 --> 00:05:11,440 All right. 59 00:05:12,820 --> 00:05:18,430 So if you put your mouse over there to tell you what that does is say it gets all sets the string containing 60 00:05:18,430 --> 00:05:25,270 the file names selected in the file dialog box if you put your mouse over that tells you what that does 61 00:05:25,780 --> 00:05:26,890 tells you what that does. 62 00:05:27,100 --> 00:05:28,000 Okay. 63 00:05:28,150 --> 00:05:34,750 So if you're not sure and just put your mouse over there and give you two tip guide the next thing you 64 00:05:34,750 --> 00:05:43,180 want to do when you are using a music player you need to specify a path where the files will be picked 65 00:05:43,180 --> 00:05:44,220 up from. 66 00:05:44,260 --> 00:05:48,020 So I'm going to reference r music player. 67 00:05:48,310 --> 00:05:50,080 Remember we declared it. 68 00:05:50,710 --> 00:05:51,480 We called it. 69 00:05:51,490 --> 00:05:53,400 I changed the name to this. 70 00:05:53,470 --> 00:05:57,780 So you put your mouse over it I tells you that's the music player. 71 00:05:58,330 --> 00:06:06,550 So I'm going to references and you need to specify a U.R.L. path that is a part for where the music 72 00:06:06,550 --> 00:06:08,180 files is coming from. 73 00:06:08,230 --> 00:06:12,900 So I'm going to set that to equals to the text box. 74 00:06:12,910 --> 00:06:21,060 So that means it will get the location of the music and displayed in the text box area. 75 00:06:22,080 --> 00:06:22,950 Okay. 76 00:06:23,010 --> 00:06:29,820 Is gonna displayed as a text that's basically what that is saying. 77 00:06:29,890 --> 00:06:34,770 So that's the code done for this button. 78 00:06:34,790 --> 00:06:41,410 I just save that and go back in to our designer and click on the play button. 79 00:06:41,410 --> 00:06:46,530 It would generate a blank again generated as top of the event handler. 80 00:06:46,960 --> 00:06:54,580 So in between this curly braces I need to specify the code because this is a play it's going to want 81 00:06:54,580 --> 00:06:58,720 when the button is clicked it will just play the music. 82 00:06:58,760 --> 00:06:59,890 This is quite easy to do. 83 00:06:59,920 --> 00:07:04,460 So again I reference the music player which is this fair ball here. 84 00:07:06,160 --> 00:07:10,810 And how attach a control v just to you can do the control. 85 00:07:10,840 --> 00:07:18,490 So there's a control called this just double click on it and then I'll attach a method to it a play 86 00:07:18,490 --> 00:07:19,950 method. 87 00:07:19,990 --> 00:07:25,060 So these are various metals you can attach to one on one for this is just the play method. 88 00:07:25,270 --> 00:07:33,220 So that's a play method and yes to a semicolon and that's it. 89 00:07:33,220 --> 00:07:39,040 So this single line of code is responsible for playing the music. 90 00:07:39,040 --> 00:07:44,640 So I'll save that go back into a designer and do the same for the pause. 91 00:07:44,650 --> 00:07:47,480 This is the event handler for the polls. 92 00:07:47,680 --> 00:07:48,810 I'm gonna save time. 93 00:07:48,820 --> 00:07:49,780 Just copy 94 00:07:52,730 --> 00:07:57,260 paste it here and just change the method to post 95 00:08:01,120 --> 00:08:03,010 code that's a lowercase 96 00:08:05,570 --> 00:08:06,320 OK. 97 00:08:06,560 --> 00:08:08,210 Go back to the control. 98 00:08:08,240 --> 00:08:09,170 Save that. 99 00:08:09,200 --> 00:08:10,430 Go back. 100 00:08:10,430 --> 00:08:18,110 Double click on the stop button generates a stop of the event handler paste same thing 101 00:08:21,080 --> 00:08:25,540 and just type in a stop notice as a stop method. 102 00:08:25,940 --> 00:08:28,170 That's all I need to do for that. 103 00:08:28,220 --> 00:08:32,050 Come here and grab the exit. 104 00:08:32,060 --> 00:08:34,220 This is different. 105 00:08:34,340 --> 00:08:37,160 I don't need to call the player. 106 00:08:37,160 --> 00:08:39,740 All I need to do is attach a close. 107 00:08:39,740 --> 00:08:41,780 There's a method called Close. 108 00:08:41,780 --> 00:08:48,170 So I want when the exit button is clicked it will close the application. 109 00:08:48,170 --> 00:08:51,530 So our code is basically finished. 110 00:08:51,830 --> 00:08:59,410 So click save and let's test the application. 111 00:08:59,410 --> 00:09:01,380 So to test we start debugging. 112 00:09:01,390 --> 00:09:08,400 We click on Start and just wait for it to load. 113 00:09:08,500 --> 00:09:08,930 All right. 114 00:09:08,950 --> 00:09:10,890 It has loaded so click on the browser. 115 00:09:10,900 --> 00:09:12,600 It should give us a dialog box. 116 00:09:12,610 --> 00:09:13,560 Excellent. 117 00:09:13,570 --> 00:09:15,130 So we need to go to music. 118 00:09:15,130 --> 00:09:17,230 You can click any music files by the way. 119 00:09:17,290 --> 00:09:23,890 I'm just gonna click on the default music sample music that Microsoft provided with the operating system. 120 00:09:23,920 --> 00:09:27,090 I just try the first one. 121 00:09:27,280 --> 00:09:31,000 I'm not sure if you can hear that this plane okay. 122 00:09:31,210 --> 00:09:33,670 That's a play you can see the path is this plane the. 123 00:09:34,360 --> 00:09:42,310 I can click on Pulse play then click on stop and then exit. 124 00:09:42,340 --> 00:09:42,850 Excellent. 125 00:09:42,880 --> 00:09:48,000 So we have successfully created a music player. 126 00:09:48,580 --> 00:09:50,230 Thank you so much for your time. 127 00:09:50,230 --> 00:09:51,220 Take care. 128 00:09:51,250 --> 00:09:52,030 Bye for now.