Enough Playing, let's create a seeker!
We know how to control volume, pause, play and even listen in on the video when something changes in it. It's time for us to create a proper seeker. Jump in it will be fun.
Video Transcript
00:00All right, so it's time for us to add a scrubber and a scrubber is going to be owed to a type of input now
00:05These inputs don't owe. I may be while you're watching this video. They are supported but in the year 2013
00:12Still in development these input devices are not a hundred percent
00:16Working you can see if you go into quirk mode
00:19org you could actually go and see that the
00:22We looked at the number in a previous video and we saw that it actually isn't supported in IE 9
00:28It's not supported oto and Firefox in its various versions of Firefox currently
00:34Working to work now on the input range
00:36Which also doesn't work on IE and Firefox at all and it's kind of supported in all the other browsers
00:41So we're gonna do it obviously check up on that and see how it's doing at any stage
00:46This wouldn't be good for a production environment at this stage
00:49But it's good to get familiar and understand how it works
00:52But still the core logic that we're learning for the player itself is completely completely
00:56Usable already at this stage. All right, so let's jump right in and we're gonna go right into our HTML and in the HTML
01:03I want it just be between the volume controllers
01:06I want to add a new scrubber to do that. I'm gonna add a new input device and it's gonna be a type of range
01:12and
01:13Again, it won't work in Firefox really only device only browser
01:17we could really test it on currently would be any other like bra opera or
01:22Safari at the stage would be probably a good ones to test it on
01:25So our minimum we want to set always default values by the way, which are very similar throughout the different input devices
01:31So the minimum value we want to set to zero the max value
01:35We want to set to 100 the default value. Let's set it to zero
01:40The step size we could define as well. So we're gonna give it a nice big step size. So it
01:46There's a lot of motion inside a lot of detail in the motion itself
01:49And there we go and we created our new input
01:52We could literally save it and if we open our browser go into Safari click on refresh look at our controllers
01:59We'll see that now we have a scrubber that isn't connected yet to the video
02:02Which will be our next step if you check this out actually in a browser such as Firefox
02:07You'll see that at least currently it does not work
02:10Alright, so we're gonna continue on and let's continue right into the code and jump right into the code in the code itself
02:15What I want to do, I'm gonna go into the JavaScript
02:17But before I do that, I'm gonna give this controller an ID as well, and I'm gonna call it
02:22Scrubber or seeker. Let's call it scrubber. Well, let's call it seeker
02:27So this is gonna be our it's gonna have an idea of seeker
02:30I'm gonna save that go into our JavaScript scroll all the way up
02:35Find our one of our
02:37Events I'm gonna take my events that this is my volume controller which has a change event
02:42Which is exactly the same type of event that we're gonna have and I'm gonna instead of that
02:46Just call our seeker get our element seeker still call the change and instead of that on
02:52seek
02:54On seek
02:55We'll call it on seek and we'll create a new function that will be called a new event function
03:01Which will be called on seek which is going to be an event
03:05So first of all, the first thing that we want to do is let's output and see what values are we getting back from our
03:11seeker to do that
03:12I'm going to use our console log and I'm gonna go right to our event and
03:17I'm gonna ask from the event the target
03:20That was clicked on and I'm gonna ask for its value and I'm gonna save it go right back into our browser
03:26click on refresh
03:28and now once we
03:30Start seeking we'll see the values are gonna start updating and we're gonna get values all the way up to a hundred and values
03:36That go all the way down to zero
03:38So now we've got a nice range between zero and a hundred
03:41The next step for us is actually to integrate that with the video itself and basically seek the video to the position of the video
03:48That we want it to be in to do that
03:50We also need to gain access to the actual position of the video currently
03:54To get the position of the video currently and how to change the position of the video currently is relatively easy as well
04:01the way to do that is I'm gonna do another console log and
04:06We actually care about two properties the video object has one is duration and the other one is video current time
04:14Now the duration is one that we don't control and it is actually
04:17Dynamically updated based on the length of our video while our video current time will reflect the current point position in the video that we're at
04:24And by that we could get a relative position knowing what position we want to be in but let's see that in action
04:30So I'm gonna save this and let me just
04:32Mute out and comment outline 27 where we're trying to get the value from our seeker itself
04:38I'm gonna go back into my browser click on refresh and this time around when I'm moving my seeker
04:43We're gonna see that one we're getting a value of not a value because it's not updated yet
04:47But if we click on the play button and the video is playing we'll be able to see that
04:52We're actually getting the value of the video currently
04:55Meaning for us that basically as until the video started loading it actually doesn't know what the range is
05:01Which is a problem?
05:02We don't want the user to be able to scrub unless the video is actually playing or the video was loaded in and because our video
05:09Wasn't loaded in at all. We don't have access to that information
05:14So what we could do is we could actually check to see if it's not a number if the value is not a number then
05:19We might not want to do anything. But for now, let's first make it work
05:23Assuming that it always works and then we'll take a separate step of fixing this issue and making sure that the scrubber won't
05:28Do anything when the values are not valid?
05:32Alright, so let's get back into our code and the first step that I want to do inside of our code is in our
05:37Seeker itself. I want to figure out based on the position itself
05:40What would be the right position to take us in our timeline now when we look at the code again?
05:45We'll see in the output itself. We'll see that the values are literally just numbers of
05:51Basically seconds what we could do then is get the actual position debate because we're one out of a hundred
05:57We could divide it by a hundred and then duplicate it by the total amount of seconds
06:01So let's see what I mean by that
06:03So basically I would take our target value and I would divide it by a hundred that would give us basically that
06:09Percentage in the video that we want to go to and then we would duplicate it by the video duration
06:15Now obviously this wouldn't work if the video has not been loaded in yet because it doesn't really know what that value would be
06:22But as soon as the video was loaded this information should be valid
06:27So if I run this again, and I go to my application again and click on a refresh
06:31We'll see first of all if I move it while the video was not loaded
06:34We're going to get a non and we're going to get a value saying that this is not a legal value
06:38Well if I click on the play button and pause it and by that making sure that my video got pre-loaded and
06:43Now I go on and I click into it
06:45I'll see that the values that I'm getting back are reflecting to the length of our actual video and
06:58Because the controller is a little bit funky and that's because these are still in development
07:03All right, but let's give it a go and let's click on that play button anyways
07:07And see that it actually works what I want to do is make the scrubber actually control the position in the video
07:12To do that is also really really easy once we've set and defined that this is our value
07:18All that's left is for us to define it and basically say that we want to take our video to that specific point in time
07:25So not only is the current time readable property
07:29It's a writable property so we could tell it exactly to go where in the video we want it to go
07:34So we're gonna save that click on refresh go into our browser again
07:37And this time around when we click into a specific spot obviously right now
07:42It's invalid because the video was not loaded, but now if we click on to a specific spot
07:46We'll see that we could actually move our video in different positions of our timeline now notice again
07:53That our scrubber isn't really working perfectly and that is because this is an experimental component and in Safari
07:58It actually isn't working that well yet because it's still in development as we could see in our
08:03chart that we were looking at earlier
08:06The chart that we were looking at earlier
08:08Which basically showed us that the basic numeric stepper is currently the range is still in development in
08:15The next video I want to continue in tying it all in together even though these components are not fully functional
08:20Just so you can see how you would integrate these type of stuff and also know how to work with the video player itself
08:26Which is stable throughout the different browsers?
