Students Save 30%! Learn & create with unlimited courses & creative assets Students Save 30%! Save Now
Advertisement
  1. Code
  2. JavaScript
Code

How to Use Easy Video Player for JavaScript

by
Difficulty:BeginnerLength:MediumLanguages:

Videos have become a key part of websites and online businesses. This is mainly because people in general are getting faster (and in most cases cheaper) internet data plans on mobile devices. Another factor that comes into play is the higher engagement with video content. People are more likely to watch and remember an interesting, well-made video than they are to read a lot of text.

If you are serious about getting more people to talk and know about your business, it's high time that you get serious about video. In this tutorial, I will help you get started right away with a step-by-step guide to using the Easy Video Player script from CodeCanyon. You can use this JavaScript library to add videos to your webpages.

Why Use Easy Video Player?

You might be wondering why you should use Easy Video Player instead of a free alternative or any other paid script.

One of the biggest reasons to choose this player is that it is feature packed. First of all, it is responsive. This means that it will look nice of devices of all sizes. It has been optimized for playing videos on both mobile devices and desktops.

It has support for multiple video qualities so that users can switch between SD, HD, and Full HD versions of a video, similar to YouTube. You can also control the playback speed of the video at runtime. It is also possible to add subtitles for multiple languages to a single video. Users can then choose the subtitles they want to display at runtime.

If you want to allow viewers to download videos, you can display an optional download button either globally or on individual videos.

Easy Video Player can also play videos from a variety of sources. You can use it to play local videos, to stream videos from a server, or to embed YouTube or Vimeo videos.

You can monetize these videos using pre-roll, mid-roll, or post-roll ads. It is also possible to add popup ads to the videos and control their show and hide time. And Easy Video Player allows you to show advertisements whenever users pause the video.

To make sure that users can't steal a video by simply crawling the page source, it's possible to encrypt the video paths. You can also password protect the videos in order to limit access to a specific set of users.

The list of features does not end here. My suggestion would be that you visit the script description page in order to read about all the features of Easy Video Player.

What We'll Be Building

Once you have completed this tutorial, you will have a fully functional video player that supports annotations. The final version of the video player will look like the image below.

Video Player Final

We will be using a video of a robin from Pixabay for this tutorial.

Getting Started

After reading that the Easy Video Player comes with so many features, you might think that it would be hard to configure or use. However, as you will see in the tutorial, getting up and running with the script is not complicated at all.

One thing that I should point out before we get started is that any local videos on your server that you play using the Easy Video Player should be located inside a folder titled content. This way, you can be sure that all the features of the player will work as expected.

After you purchase the Easy Video Player from CodeCanyon, you will be able to download the script as well as the documentation. The documentation contains a lot of working examples that can be added directly to your website by simply changing the source path or URL for the videos. The fastest and easiest way for you to quickly embed videos in your webpage using this player is to use parts from the working examples themselves. Just make appropriate changes to suit your own needs.

The first step would be to include the CSS and JavaScript files in your webpage.

By default, the player keeps CSS file in the content folder and JavaScript file in the java folder. If you change the location of these files, make sure that you update their path on the webpage as well.

Now, you have to specify a container for the video player. This container div will have a unique id which is passed to the constructor of Easy Video Player. You can set the CSS property margin to auto for this div in order to center it horizontally on the webpage, but that is optional.

Add the following HTML inside the body of the webpage where you want the video player to appear.

While it is not necessary, you can add some CSS in order to make the video player look even nicer or to position it properly on the webpage. Here is the CSS that we would use for this purpose.

Initializing the Video Player

Now, you simply need to initialize the Easy Video Player by passing a bunch of parameters to the constructor. These parameters control all aspects of the video player, so you should read the documentation to understand how each of them works. In this tutorial, I will give you a brief overview of the options that we will modify in our own player.

This is the code that you have to put in your webpage for initializing the player. It might look very long and complicated, but the parameters have self-explanatory names, and they will have the same value from one player instance to another. Most of the time, you will be able to directly take the initialization parameters from the examples in the documentation and make changes as needed.

Two parameters that have to be unique every time are instanceName and parentId. The parentId parameter is the id of the container for your video. The value of the instanceName parameter is used to identify the player when calling methods like play().

The videoSource parameter is used to specify the path to different versions of the same video so that users can play it in SD, HD, or Full HD format. The posterPath parameter specifies the path of the image file that shows up before the video starts playing.

A lot of other parameters are used to control the spacing, color, or background of different UI elements used in the player. If you load the webpage in a browser now, you should see something similar to the image below.

Video Player UI

Adding Annotations to Your Video

There are many situations where you will want to give the viewers some additional information while they are watching a video. Annotations are very helpful in that situation. Luckily, Easy Video Player provides a convenient way of adding annotations to your videos.

You just need to use a little HTML with special data attributes. In our case, we will use annotations to tell readers a fact about robins and then link to Wikipedia if they want to read more about the bird. Here is the markup that you have to add to the webpage. It might be better to add it right below the video player container.

Setting display to none for the annotations will hide them from appearing the webpage. The attributes specified with each annotation will determine when and where they appear in the video. The distance of the annotations from the left and top side can be specified using the data-top and data-left attributes. The data-start-time and data-end-time attributes determine when the annotations will show up and disappear. You can also give users the option to close the annotations manually by setting the data-show-close-button attribute to true. You can read about all other attributes in the documentation available with the download.

Keep in mind that the annotations don't start working as soon as you add them to the webpage. Right now, the video player does not know about their existence. So you have to specify a couple of parameters in its constructor to help it determine where to find the annotations.

If someone plays the video now, they will see the annotations after the specified time, as in the image below.

Video Player Annotations

Final Thoughts

In this tutorial, we have created a feature-rich, fully functional responsive video player which supports annotations using the Easy Video Player script from CodeCanyon.

This is just one of the ways of using the plugin. The plugin also offers a lot of other features which increase its usefulness. For example, the script allows you to integrate different kinds of ads in your video to help you monetize your content. You can also use it to play videos inside a lightbox.

Once you purchase this script, you will get six months of free support and lifetime free updates. The plugin is well worth its price due to all the features it offers.

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.