1 00:00:01,230 --> 00:00:02,470 ‫Welcome back. 2 00:00:02,490 --> 00:00:08,040 ‫It's challenge time again and I hope you manage to check out the whole inheritance video and understand 3 00:00:08,040 --> 00:00:13,920 ‫what was going on and how to create the post and the image post and how they correlate to each other 4 00:00:13,920 --> 00:00:15,630 ‫so how they are connected to each other. 5 00:00:15,630 --> 00:00:21,030 ‫So that image post is the deriving class and post is the base class. 6 00:00:21,030 --> 00:00:28,560 ‫Because now the little challenge is to create a new class called Video Post, which is a driving class 7 00:00:28,560 --> 00:00:31,830 ‫with the property video URL and length. 8 00:00:31,980 --> 00:00:37,290 ‫So these are unique properties to that video post. 9 00:00:37,290 --> 00:00:42,960 ‫So just imagine we are still in this post type of thing and we have normal posts which are just text 10 00:00:42,960 --> 00:00:46,680 ‫then we have or which can be text but anything else as well. 11 00:00:46,680 --> 00:00:52,650 ‫Then we have an image post which also has an image URL and now what we want to have is a video post 12 00:00:52,650 --> 00:00:58,590 ‫where we actually have a video URL instead of an image URL and also the length of the video. 13 00:00:58,590 --> 00:01:02,220 ‫So these are the information that we want to have about every video post. 14 00:01:02,220 --> 00:01:08,010 ‫So now create the required constructors to create a video post adjusted to string method accordingly, 15 00:01:08,010 --> 00:01:15,120 ‫because we have seen in the image post that the two string method adds some more information based on 16 00:01:15,150 --> 00:01:17,520 ‫the information that was sent here already. 17 00:01:17,520 --> 00:01:23,490 ‫But we want to know even more about the video post than we know about the post. 18 00:01:23,760 --> 00:01:29,220 ‫So the just two string method then create an instance of video post. 19 00:01:29,220 --> 00:01:31,980 ‫So pretty much the same thing as we did here with the image post. 20 00:01:31,980 --> 00:01:35,550 ‫Just create one and then write it onto the console. 21 00:01:35,550 --> 00:01:42,510 ‫So maybe I should add that and use the two string method on it. 22 00:01:43,410 --> 00:01:48,180 ‫Then if you feel like a real challenge, then you can go ahead with the more advanced stuff. 23 00:01:48,180 --> 00:01:51,720 ‫So use a timer and a callback method here. 24 00:01:51,720 --> 00:01:52,680 ‫You can Google it. 25 00:01:52,710 --> 00:01:57,360 ‫You can simply yeah, you can try to do it yourself or you can Google it. 26 00:01:57,360 --> 00:02:05,010 ‫So the idea is that our video post has a method called play and one that is called stop, and when play 27 00:02:05,010 --> 00:02:09,660 ‫is called then they should write the current duration of the video. 28 00:02:09,660 --> 00:02:15,510 ‫So every single second there should be a tick writing at which second of the video we currently are. 29 00:02:15,540 --> 00:02:23,970 ‫And then one stop is pressed, the timer is stopped and there's also a text written stop that and that's 30 00:02:23,970 --> 00:02:27,060 ‫best with double P and yeah, that's pretty much it. 31 00:02:27,060 --> 00:02:31,740 ‫So play the video after creating the instance and pause it when the user presses any key. 32 00:02:31,740 --> 00:02:35,130 ‫Or maybe stop it when the user presses any key. 33 00:02:35,130 --> 00:02:38,610 ‫So by presses any key, I just mean you have a real line there. 34 00:02:38,610 --> 00:02:40,800 ‫So just keep it simple or read key better. 35 00:02:40,890 --> 00:02:48,840 ‫So just keep it simple and that what you see here will help you to create even video players later on. 36 00:02:48,840 --> 00:02:52,890 ‫So that's really just a basic concept and use timers here. 37 00:02:52,980 --> 00:02:55,500 ‫But as I said, this one is the more advanced part. 38 00:02:55,500 --> 00:02:59,490 ‫If you don't feel like doing it or if it's too difficult, then it's fine as well. 39 00:02:59,490 --> 00:03:05,610 ‫You can just check out the video, but I really advise you to check this out because it will teach you 40 00:03:05,610 --> 00:03:09,060 ‫how to use timers and callbacks by just googling it. 41 00:03:09,060 --> 00:03:15,450 ‫And it's best to just try yourself to experience how it's working and then you will definitely remember 42 00:03:15,450 --> 00:03:17,490 ‫it next time you want to use timers. 43 00:03:17,970 --> 00:03:18,450 ‫All right. 44 00:03:18,450 --> 00:03:21,810 ‫So pause the video now and try to do this challenge. 45 00:03:24,200 --> 00:03:24,800 ‫Already. 46 00:03:24,800 --> 00:03:26,030 ‫I hope you tried it. 47 00:03:26,060 --> 00:03:29,090 ‫First of all, we, of course, need a new class. 48 00:03:31,080 --> 00:03:33,960 ‫And it's going to be our video post. 49 00:03:36,000 --> 00:03:40,050 ‫And now that video post should inherit from post. 50 00:03:42,600 --> 00:03:49,290 ‫And here, as I said, we would have a different property or actually two different properties, which 51 00:03:49,290 --> 00:03:50,610 ‫we didn't have before. 52 00:03:51,150 --> 00:04:02,100 ‫And one of them is the video URL protected string video u r URL and it's a get and a set. 53 00:04:03,630 --> 00:04:14,790 ‫Then the same thing with the length protected int length with a capital l, it's best also get and set. 54 00:04:15,480 --> 00:04:21,390 ‫Next we need a constructor, so let's create a constructor here. 55 00:04:21,600 --> 00:04:26,130 ‫Public video post and I'm going to leave it empty again. 56 00:04:26,130 --> 00:04:34,800 ‫The same approach as we had in our image post here where we simply created this empty constructor because 57 00:04:34,800 --> 00:04:37,310 ‫neither constructor calls a base clause. 58 00:04:37,320 --> 00:04:39,480 ‫The one from the post will be called. 59 00:04:39,480 --> 00:04:40,860 ‫So that one here. 60 00:04:41,070 --> 00:04:47,010 ‫So if we have an empty video post, the post method will be called or the post constructor will be called 61 00:04:47,460 --> 00:04:48,630 ‫the default one. 62 00:04:48,630 --> 00:04:54,060 ‫But we also have one where we actually hand over the required information. 63 00:04:54,060 --> 00:05:01,560 ‫So for example, for a video post, what's interesting there, well, it's on one hand the title again 64 00:05:01,560 --> 00:05:13,020 ‫string title, then the username so sent by username, then the URL, string video URL and the bool 65 00:05:13,470 --> 00:05:18,690 ‫is published and even the length. 66 00:05:18,690 --> 00:05:21,240 ‫So in length is also useful here. 67 00:05:21,720 --> 00:05:22,080 ‫All right. 68 00:05:22,080 --> 00:05:26,700 ‫So quite a long constructor in terms of its parameters. 69 00:05:26,700 --> 00:05:34,530 ‫And now we, of course, need to use this dot and of course, this dot get ID or get next ID is going 70 00:05:34,530 --> 00:05:36,330 ‫to be required here as well. 71 00:05:36,330 --> 00:05:39,960 ‫So we want to not create an ID that is already there. 72 00:05:39,960 --> 00:05:42,420 ‫We want to go ahead and use the next ID. 73 00:05:42,450 --> 00:05:49,890 ‫And as you might recall, this get next ID is returning and increased or incremented current post ID, 74 00:05:49,920 --> 00:05:52,800 ‫which is a static variable. 75 00:05:52,800 --> 00:06:00,510 ‫So it's unique for this whole program, which means that it will be overridden with a new value or pretty 76 00:06:00,510 --> 00:06:06,960 ‫much we will simply get the new value and it's always going to be just one ID once. 77 00:06:06,960 --> 00:06:10,200 ‫So each ID is only going to be unique and that's really important here. 78 00:06:10,200 --> 00:06:18,570 ‫Then the title is going to be title and actually we can even go ahead and copy that from here because 79 00:06:18,570 --> 00:06:19,590 ‫it's the same approach. 80 00:06:19,590 --> 00:06:20,100 ‫Right. 81 00:06:20,340 --> 00:06:21,330 ‫And. 82 00:06:23,250 --> 00:06:28,950 ‫We can simply import it here and now we go ahead with our unique URLs. 83 00:06:28,950 --> 00:06:45,960 ‫So property video URL is a member of video post and actually I called it accidentally is published but 84 00:06:45,960 --> 00:06:53,280 ‫it should be as public with your post but not of post. 85 00:06:53,820 --> 00:07:01,680 ‫And that will be this video URL is going to be video URL and this length is going to be length. 86 00:07:01,950 --> 00:07:10,740 ‫So whatever is given over here as the argument should be taken into the object's properties which are 87 00:07:10,740 --> 00:07:15,000 ‫length video URL and of course the one that we inherited from post. 88 00:07:15,420 --> 00:07:18,150 ‫All right, so that's our constructor. 89 00:07:18,150 --> 00:07:22,740 ‫And now we need to have a two string method. 90 00:07:22,770 --> 00:07:26,400 ‫As we said, we would need a specific two string method. 91 00:07:26,400 --> 00:07:33,270 ‫And it's easiest if we just copy it from the image post and we override it again. 92 00:07:33,270 --> 00:07:36,420 ‫So public overwrite string to string. 93 00:07:36,420 --> 00:07:44,850 ‫So we override the method of our post class, which means we override this method here, which again 94 00:07:44,850 --> 00:07:46,590 ‫overrides from system that object. 95 00:07:46,590 --> 00:07:51,090 ‫So that's the beauty about inheritance you can override and override. 96 00:07:51,090 --> 00:07:55,620 ‫So now we have the string format and it might be a little different. 97 00:07:55,620 --> 00:07:56,520 ‫Well, different. 98 00:07:56,520 --> 00:07:58,530 ‫We can decide whether we want that or not. 99 00:07:58,530 --> 00:08:03,450 ‫We could send the length in here or we could leave it as is. 100 00:08:03,570 --> 00:08:09,090 ‫So the only difference would be not the image URL but the video URL are required. 101 00:08:09,540 --> 00:08:12,780 ‫And if you feel like it, you can add the length in here as well. 102 00:08:12,780 --> 00:08:15,870 ‫So if you want to for inform about that. 103 00:08:15,870 --> 00:08:17,580 ‫So maybe let's just do that. 104 00:08:17,610 --> 00:08:23,010 ‫Maybe it's easiest to just do that and that will be for done. 105 00:08:23,010 --> 00:08:31,890 ‫And in here I'm just going to add this dot length and I separate by comma. 106 00:08:31,890 --> 00:08:37,080 ‫So now in order to make it more readable, I'm just going to use a second line here. 107 00:08:37,930 --> 00:08:40,630 ‫All right, so that's our two string method. 108 00:08:40,630 --> 00:08:45,730 ‫And now we can go ahead into our posts or actually in our program class. 109 00:08:45,730 --> 00:08:49,000 ‫And in here we can create a video post. 110 00:08:50,290 --> 00:08:53,620 ‫Video post we're going to call it video post. 111 00:08:53,620 --> 00:08:58,360 ‫One is going to be a new video post and we could go ahead and do like that. 112 00:08:58,360 --> 00:09:04,600 ‫But then it would be an empty post, which is our ID zero post, like this one here, which just has 113 00:09:04,600 --> 00:09:06,130 ‫my first post as info. 114 00:09:06,130 --> 00:09:09,340 ‫It's public and it's by Dennis Panetta, but that's not very interesting. 115 00:09:09,340 --> 00:09:16,780 ‫So we are going to create one with our own unique values which will have a unique ID because we created 116 00:09:16,780 --> 00:09:17,470 ‫it that way. 117 00:09:17,470 --> 00:09:24,400 ‫So we can go ahead and here and I'm going to say this is a failed video and I uploaded it. 118 00:09:24,400 --> 00:09:33,040 ‫So Dennis Panetta uploaded it and you can find it under https video dot com slash fail video or something 119 00:09:33,040 --> 00:09:33,430 ‫like that. 120 00:09:33,430 --> 00:09:40,060 ‫It's just a fake ID or a fake link video dot com slash fail video. 121 00:09:41,770 --> 00:09:48,550 ‫And then as this is too long for one row, I'm just gonna put it over to the next one. 122 00:09:48,760 --> 00:09:54,190 ‫What we need now, if you check it out here, there are two overloads, so let's check out the overloads. 123 00:09:54,760 --> 00:10:02,560 ‫We need to have an additional information about the access or whether it's public or not. 124 00:10:02,560 --> 00:10:05,530 ‫And here we are again, public, and now we need the length. 125 00:10:05,530 --> 00:10:09,940 ‫So let's say this video is 15 seconds long or maybe 10 seconds long. 126 00:10:10,420 --> 00:10:11,200 ‫Ten is fine. 127 00:10:11,440 --> 00:10:13,600 ‫So just make it 10 seconds long. 128 00:10:14,080 --> 00:10:14,980 ‫And now. 129 00:10:15,880 --> 00:10:16,920 ‫That's pretty much it. 130 00:10:16,930 --> 00:10:23,770 ‫So we can already start our program and we should see the information about our video posts. 131 00:10:25,030 --> 00:10:28,120 ‫And of course, the more challenging part is still missing. 132 00:10:28,120 --> 00:10:34,750 ‫So that we are check out my new shoes that images dot com and actually we don't call the method yet 133 00:10:34,900 --> 00:10:37,300 ‫the two string method so maybe we should do that. 134 00:10:39,130 --> 00:10:44,620 ‫And next we need to call this video posts to string method. 135 00:10:45,490 --> 00:10:46,120 ‫All right. 136 00:10:46,450 --> 00:10:54,370 ‫So by the way, if you were wondering video that you can see, there are multiple methods here already. 137 00:10:54,370 --> 00:10:56,260 ‫And we didn't create those numbers. 138 00:10:56,260 --> 00:10:57,490 ‫They were just there. 139 00:10:57,730 --> 00:11:06,280 ‫And that is because we inherit from post, which again inherits from the system that object. 140 00:11:06,280 --> 00:11:13,120 ‫By the way, if you check it out for post one as well, post one dot, you can see those methods there 141 00:11:13,120 --> 00:11:13,420 ‫as well. 142 00:11:13,420 --> 00:11:16,060 ‫So equals get hashCode get type update. 143 00:11:16,060 --> 00:11:21,160 ‫So these methods, they are inherited from the system object class. 144 00:11:21,430 --> 00:11:23,380 ‫All right, so now we have the two string. 145 00:11:23,380 --> 00:11:26,980 ‫So now we of course need to put that into a console right line. 146 00:11:26,980 --> 00:11:33,160 ‫Actually, let's copy this code here and replace image post by video post one. 147 00:11:34,120 --> 00:11:34,720 ‫All right. 148 00:11:34,720 --> 00:11:37,600 ‫And now we can start it and there we are. 149 00:11:37,990 --> 00:11:46,990 ‫So one things for the birthday wishes, then three As you can see, the video post has a different ID 150 00:11:46,990 --> 00:11:50,020 ‫than our image post. 151 00:11:50,110 --> 00:11:52,090 ‫So we have one, three and two. 152 00:11:52,120 --> 00:11:55,720 ‫That is just the order in which we are writing them onto the console. 153 00:11:55,720 --> 00:12:01,690 ‫So if you check it out here at the video post, even though it's created after the image post we printed 154 00:12:01,690 --> 00:12:06,220 ‫out earlier, and that gives us this wrong order if you want. 155 00:12:06,220 --> 00:12:11,410 ‫But the order is not that important if you well, it's based on what you want to show. 156 00:12:11,410 --> 00:12:16,270 ‫So if you want to show the images based on the order that they were created or the posts in general, 157 00:12:16,270 --> 00:12:21,820 ‫based on the order that they were created, or you want to show the latest 1/1, those kind of things, 158 00:12:21,820 --> 00:12:23,230 ‫then the order of course matters. 159 00:12:23,230 --> 00:12:25,810 ‫But in our case it's really good that we have it that way. 160 00:12:25,810 --> 00:12:35,410 ‫So you can see that the ID is set up and at the moment when the object is created, so ID three and 161 00:12:35,410 --> 00:12:40,330 ‫ID two and another at the moment when it is called like here like the two string method. 162 00:12:40,330 --> 00:12:42,430 ‫So if you would like to have the correct. 163 00:12:43,550 --> 00:12:50,390 ‫Order for the order in which they are created would just go ahead like this. 164 00:12:51,020 --> 00:12:52,880 ‫And now we can see one, two and three. 165 00:12:52,880 --> 00:12:54,710 ‫So thanks for the birthday wishes. 166 00:12:54,710 --> 00:12:58,970 ‫Then our image with the new shoes than the fail video by Dennis Panetta. 167 00:12:58,970 --> 00:13:03,230 ‫And as you can see here, the length of ten is sent as well. 168 00:13:03,650 --> 00:13:04,100 ‫All right. 169 00:13:04,100 --> 00:13:05,600 ‫So that was part one. 170 00:13:05,600 --> 00:13:12,950 ‫And now the more advanced challenge, which is to create a timer and a callback method, which is called 171 00:13:12,950 --> 00:13:19,130 ‫every second and should inform us about the duration of the video or the current duration of the video. 172 00:13:19,130 --> 00:13:22,250 ‫And of course, we need to create the fields as required. 173 00:13:22,250 --> 00:13:25,340 ‫So we will need some additional fields in here. 174 00:13:25,340 --> 00:13:30,170 ‫For example, we will need to know at which point in the video we are. 175 00:13:30,170 --> 00:13:37,850 ‫So let's go ahead and actually let's create the fields before the properties. 176 00:13:38,000 --> 00:13:43,580 ‫So here properties and now let's create the memory fields. 177 00:13:46,590 --> 00:13:56,460 ‫And what is going to be a protected boolean is playing that is useful because if a video is playing 178 00:13:56,460 --> 00:13:57,540 ‫then you can pause it. 179 00:13:57,540 --> 00:14:00,150 ‫If it's not playing, then you can stop, start it. 180 00:14:00,150 --> 00:14:01,770 ‫So that's really important. 181 00:14:02,010 --> 00:14:06,690 ‫So if a video is already playing, you wouldn't want to start it playing. 182 00:14:06,810 --> 00:14:18,930 ‫That's why we have this helper boolean here and then we need a protected int cur duration. 183 00:14:20,730 --> 00:14:26,250 ‫It's zero now in order to call the timer. 184 00:14:28,320 --> 00:14:40,530 ‫We create a new method, let's create a public void play method and let's create the stop method as 185 00:14:40,530 --> 00:14:41,190 ‫well. 186 00:14:42,090 --> 00:14:47,010 ‫So public void, stop. 187 00:14:48,510 --> 00:14:50,460 ‫Now, what do we want to do here? 188 00:14:50,490 --> 00:14:54,630 ‫Well, first of all, let's just write something onto the console, like playing. 189 00:14:55,620 --> 00:14:56,010 ‫So we. 190 00:14:56,080 --> 00:14:56,700 ‫Okay. 191 00:14:56,730 --> 00:14:59,910 ‫The play was started or playing. 192 00:14:59,910 --> 00:15:01,130 ‫The video was started. 193 00:15:01,140 --> 00:15:04,470 ‫And in here I want to set the timer. 194 00:15:04,470 --> 00:15:06,450 ‫And first let's create the timer. 195 00:15:06,450 --> 00:15:13,840 ‫So we are going to need a timer here, timer, and I'm going to call it timer. 196 00:15:13,860 --> 00:15:20,250 ‫Now, in order to use timer, we need to use system dot threading. 197 00:15:20,700 --> 00:15:23,700 ‫That's the one that I need using system threading. 198 00:15:23,940 --> 00:15:31,530 ‫And now what we can go ahead and do is to initialize the timer whenever place pressed. 199 00:15:32,190 --> 00:15:35,970 ‫So timer is going to be a new. 200 00:15:38,230 --> 00:15:38,980 ‫Timer. 201 00:15:39,730 --> 00:15:45,370 ‫Timer callback should be the method that is called after. 202 00:15:46,090 --> 00:15:49,800 ‫What we need to state here, which I'm going to just say is no. 203 00:15:49,810 --> 00:15:55,750 ‫So as you can see, you need a timer callback, then you need an object, you need to do time and a 204 00:15:55,750 --> 00:16:01,410 ‫period and the due time is when it should start and the period should be how often should repeat it, 205 00:16:01,420 --> 00:16:03,970 ‫or in which time frame it should be repeated. 206 00:16:03,970 --> 00:16:09,880 ‫So the due time, I'm going to set it as zero and the period is 1000 milliseconds. 207 00:16:09,880 --> 00:16:16,690 ‫So now of course I need to have this timer callback method and I'm just going to go ahead and create 208 00:16:16,690 --> 00:16:16,990 ‫that. 209 00:16:16,990 --> 00:16:23,170 ‫And it should be a private method because I don't want anybody else to call it only this class itself. 210 00:16:23,170 --> 00:16:30,700 ‫So only void video posts should be able to call this timer callback and the timer callback while it 211 00:16:30,700 --> 00:16:34,210 ‫needs an object as its parameter. 212 00:16:34,210 --> 00:16:43,240 ‫And just going to say, oh, I'm going to call it oh, and now I can check if the current duration is 213 00:16:43,240 --> 00:16:53,080 ‫below the length of the video, then I want to go ahead and increase the current duration by one and 214 00:16:53,170 --> 00:16:55,180 ‫display onto the console. 215 00:16:55,630 --> 00:17:09,640 ‫So see w video at 0 seconds like this and then we need to have the current duration. 216 00:17:09,880 --> 00:17:12,820 ‫So what this will do is simply right onto the console. 217 00:17:12,820 --> 00:17:19,930 ‫And now in order to force the garbage collector for this video, we're just going to use GC Dot collection 218 00:17:20,260 --> 00:17:22,660 ‫so that will clean up any mess. 219 00:17:23,740 --> 00:17:33,610 ‫And by the way, else, if the current duration is not below the length, so that means that the video 220 00:17:33,610 --> 00:17:34,330 ‫is over. 221 00:17:34,330 --> 00:17:36,130 ‫We want to call the stop method. 222 00:17:36,130 --> 00:17:38,650 ‫So in here we're just going to call stop. 223 00:17:41,290 --> 00:17:43,840 ‫And now stop needs, of course, to be implemented. 224 00:17:44,500 --> 00:17:55,690 ‫So let's check out what we need in stop console dot right line and this is going to be stopped at and 225 00:17:55,690 --> 00:18:01,000 ‫then we just say at which second we stop the video and I'm going to say courage, duration. 226 00:18:02,470 --> 00:18:09,220 ‫And of course, we need to reset the current duration to being zero and stop the timer and stop the 227 00:18:09,220 --> 00:18:09,430 ‫time. 228 00:18:09,430 --> 00:18:11,290 ‫We call it this post method. 229 00:18:11,350 --> 00:18:15,070 ‫This one just cleans up the timer or stops the timer and resets it. 230 00:18:16,220 --> 00:18:20,150 ‫Now in order to make this even cleaner. 231 00:18:20,450 --> 00:18:26,290 ‫As I said, we have this is playing field and we can use that in our play method. 232 00:18:26,300 --> 00:18:30,350 ‫So we could say only if is playing this false. 233 00:18:30,350 --> 00:18:33,290 ‫So we use the exclamation mark at to start. 234 00:18:33,470 --> 00:18:37,880 ‫Only then I want to do this. 235 00:18:37,880 --> 00:18:39,410 ‫Only then I want to start playing. 236 00:18:39,410 --> 00:18:41,900 ‫Only then I want to initialize the timer. 237 00:18:42,110 --> 00:18:44,840 ‫And if it's not playing, then nothing should happen. 238 00:18:46,840 --> 00:18:50,770 ‫And here we can do the same. 239 00:18:50,770 --> 00:18:56,800 ‫So in the stop method we can check if is playing is true. 240 00:18:56,800 --> 00:19:00,370 ‫So only if the player is playing, we should be able to stop it. 241 00:19:02,410 --> 00:19:02,890 ‫All right. 242 00:19:02,890 --> 00:19:07,930 ‫So that's it for our video post class. 243 00:19:07,930 --> 00:19:16,150 ‫So now we should be able to check it out by going to our program and at one point start creating or 244 00:19:16,150 --> 00:19:17,470 ‫start playing the video. 245 00:19:17,650 --> 00:19:24,700 ‫So what I'm going to do is after I have created the video post, I'm going to play it. 246 00:19:25,990 --> 00:19:35,230 ‫And then as I said, I would like to leave the or let the user actually stop playing the video. 247 00:19:35,230 --> 00:19:50,320 ‫So how do we do that console that read key and afterwards I will call the stop method and in between, 248 00:19:50,320 --> 00:19:53,710 ‫of course I would like to inform the user about what you should do. 249 00:19:53,890 --> 00:20:03,340 ‫So I'm going to use C.W. here, console right line and I'm going to say press any key to stop the video. 250 00:20:05,740 --> 00:20:06,280 ‫All right. 251 00:20:06,280 --> 00:20:08,230 ‫And now we can check it out. 252 00:20:09,340 --> 00:20:15,210 ‫And see whether what we have built there actually works so that we are press any key to stop the video? 253 00:20:15,220 --> 00:20:22,600 ‫As you can see, the video has started and it's running and let's say I want to press any key and actually 254 00:20:22,600 --> 00:20:23,350 ‫I was too slow. 255 00:20:23,350 --> 00:20:27,000 ‫So the video went through and after 10 seconds it stopped. 256 00:20:27,010 --> 00:20:28,030 ‫And why is that? 257 00:20:28,060 --> 00:20:30,940 ‫Well, that's because our video is only 10 seconds long. 258 00:20:30,940 --> 00:20:35,050 ‫So we have this length property, which indicates how long the video is. 259 00:20:35,350 --> 00:20:43,390 ‫So let's say we create a different video and we want this video, or actually we changed the duration 260 00:20:43,390 --> 00:20:46,690 ‫of our video post to just being 5 seconds. 261 00:20:48,360 --> 00:20:50,520 ‫So let's just do that and run it again. 262 00:20:51,600 --> 00:20:54,120 ‫And then you will see after 5 seconds it will stop. 263 00:20:56,340 --> 00:20:57,210 ‫And there we are. 264 00:20:57,330 --> 00:20:58,230 ‫Video finished. 265 00:20:58,230 --> 00:20:59,880 ‫So now let's stop it manually. 266 00:21:00,120 --> 00:21:01,230 ‫Let's run it again. 267 00:21:02,160 --> 00:21:02,770 ‫There we are. 268 00:21:02,790 --> 00:21:05,220 ‫And let's press any key to stop the video. 269 00:21:06,330 --> 00:21:07,710 ‫And it's not working. 270 00:21:07,710 --> 00:21:12,630 ‫And that is because if we check the post Claus is playing is wrong. 271 00:21:13,020 --> 00:21:15,620 ‫And that's why is playing is never true. 272 00:21:15,630 --> 00:21:20,130 ‫So what we need to do here is to set is playing to true, of course. 273 00:21:20,520 --> 00:21:24,330 ‫And the same goes for our stop here. 274 00:21:24,510 --> 00:21:30,420 ‫So we say is playing is false. 275 00:21:33,950 --> 00:21:36,590 ‫All right, so now let's go back here and let's run it again. 276 00:21:36,830 --> 00:21:44,900 ‫And now the video is running and I post it or I stopped it and it says Stopped at four, and we could 277 00:21:44,900 --> 00:21:50,450 ‫even go ahead and change it to stop that 4 seconds like this. 278 00:21:50,810 --> 00:21:55,190 ‫And in order to have more time, as you saw, it was pretty close. 279 00:21:55,190 --> 00:21:57,350 ‫I'm going to give myself 10 seconds again. 280 00:21:57,770 --> 00:21:59,990 ‫So I drag it over. 281 00:22:00,080 --> 00:22:03,950 ‫Here I am and I stop it. 282 00:22:03,950 --> 00:22:05,540 ‫So I pressed the enter key. 283 00:22:07,420 --> 00:22:08,290 ‫Okey dokey. 284 00:22:08,320 --> 00:22:10,780 ‫So that was quite a challenge. 285 00:22:11,050 --> 00:22:14,040 ‫I hope you manage to do that, even the more advanced thing. 286 00:22:14,050 --> 00:22:21,640 ‫But what's really interesting, and I haven't touched upon it too much is this whole timer method. 287 00:22:21,640 --> 00:22:25,480 ‫So if you used it, then you understand what is going on or this time a class. 288 00:22:25,480 --> 00:22:31,750 ‫So there is a class called timer and you can use it in order to use timer methods or in order to use 289 00:22:31,750 --> 00:22:32,470 ‫a timer. 290 00:22:32,470 --> 00:22:39,880 ‫So what it does is you go ahead and create a new timer object and you can use a timer callback and the 291 00:22:39,880 --> 00:22:47,860 ‫timer callback allows you to be called or to execute some code each time that this duration is over. 292 00:22:47,860 --> 00:22:55,870 ‫So each time that the time frame that you assigned here so in my case 1000 milliseconds is over or this 293 00:22:55,870 --> 00:22:58,630 ‫period, then this timer callback will be called. 294 00:22:58,630 --> 00:23:01,860 ‫So it will be called in my case every single second. 295 00:23:01,870 --> 00:23:06,280 ‫That's why it says video at 1/2, 2 seconds and so forth. 296 00:23:06,460 --> 00:23:13,780 ‫That's pretty cool because now you can go ahead and create timer based methods or timer based programs 297 00:23:13,780 --> 00:23:14,530 ‫pretty much. 298 00:23:14,530 --> 00:23:20,170 ‫And you could create a whole timer where the user can play around with and do even more than we just 299 00:23:20,170 --> 00:23:20,800 ‫did here. 300 00:23:21,070 --> 00:23:26,350 ‫So the general idea is you create a new timer, you create a timer callback, which is this timer callback 301 00:23:26,350 --> 00:23:29,200 ‫method which needs an object that's important. 302 00:23:29,200 --> 00:23:34,060 ‫And then in here you can go ahead or within the curly brackets, you can go ahead and execute your code 303 00:23:34,060 --> 00:23:35,050 ‫regularly. 304 00:23:35,350 --> 00:23:38,620 ‫And that will be every so in so many seconds. 305 00:23:38,620 --> 00:23:45,880 ‫Then of course, the timer object has, if you look at it, a due time, which you can assign, which 306 00:23:45,880 --> 00:23:49,360 ‫is this one here, and a state which you can assign. 307 00:23:49,360 --> 00:23:51,310 ‫And I just use the state null. 308 00:23:51,910 --> 00:23:52,510 ‫All right. 309 00:23:52,510 --> 00:23:54,070 ‫So that was it. 310 00:23:54,250 --> 00:24:01,990 ‫And we are going to go ahead and see even more what we can do with inheritance and object oriented programming 311 00:24:01,990 --> 00:24:02,890 ‫in the next videos. 312 00:24:02,890 --> 00:24:04,000 ‫So see you there.