1. Web Design
  2. HTML/CSS
  3. HTML

How to Use Easy Video Player for JavaScript

Scroll to top

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 FinalVideo Player FinalVideo 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.

1
<!DOCTYPE html>
2
<html lang="en">
3
  <head>
4
    <title> Easy Video Player - TutsPlus Example </title>
5
    <meta charset="utf-8">
6
    <meta name="viewport" content="width=device-width, initial-scale=1">
7
    <link rel="stylesheet" href="content/global.css">
8
    <script type="text/javascript" src="java/FWDEVPlayer.js"></script>      
9
  </head>
10
  <body>
11
  
12
    <!-- WE WILL ADD OUR VIDEO PLAYER HERE -->
13
  
14
  </body>
15
</html>

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.

1
<div id="topVideo"></div>

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.

1
body {
2
	background-color: #efefef;
3
	cursor: auto;
4
}
5
6
#topVideo {
7
	box-shadow: 0 0 20px #989898, 0 0 50px #b0b0b0;
8
	margin: 50px auto;
9
}

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.

1
<script type="text/javascript">
2
FWDEVPUtils.onReady(function(){
3
4
	FWDEVPlayer.videoStartBehaviour = "pause";
5
	
6
	new FWDEVPlayer({		
7
		//main settings

8
		instanceName:"player1",
9
		parentId:"topVideo",
10
		mainFolderPath:"content",
11
		initializeOnlyWhenVisible:"no",
12
		skinPath:"minimal_skin_white",
13
		displayType:"responsive",
14
		fillEntireVideoScreen:"no",
15
		playsinline:"yes",
16
		autoScale:"yes",
17
		openDownloadLinkOnMobile:"no",
18
		useVectorIcons:"no",
19
		useResumeOnPlay:"no",
20
		goFullScreenOnButtonPlay:"no",
21
		useHEXColorsForSkin:"no",
22
		normalHEXButtonsColor:"#FF0000",
23
		selectedHEXButtonsColor:"#FFFFFF",
24
		privateVideoPassword:"428c841430ea18a70f7b06525d4b748a",
25
		startAtTime:"",
26
		stopAtTime:"",
27
		startAtVideoSource:2,
28
		videoSource:[
29
			{source:"content/videos/robin_sd.mp4", label:"small version"},
30
			{source:"content/videos/robin_hd.mp4", label:"hd720"},
31
			{source:"content/videos/robin_full_hd.mp4", label:"hd1080"}
32
		],
33
		posterPath:"content/posters/robin-poster.png",
34
		showErrorInfo:"yes",
35
		fillEntireScreenWithPoster:"yes",
36
		disableDoubleClickFullscreen:"no",
37
		addKeyboardSupport:"yes",
38
		useChromeless:"no",
39
		showPreloader:"yes",
40
		preloaderColors:["#999999", "#FFFFFF"],
41
		autoPlay:"no",
42
		enableAutoplayOnMobile:"no",
43
		loop:"no",
44
		scrubAtTimeAtFirstPlay:"00:00:00",
45
		maxWidth:980,
46
		maxHeight:552,
47
		volume:.8,
48
		//logo settings

49
		showLogo:"yes",
50
		hideLogoWithController:"yes",
51
		logoPosition:"topRight",
52
		logoLink:"https://code.tutsplus.com/",
53
		logoMargins:5,
54
		//controller settings

55
		showController:"yes",
56
		showDefaultControllerForVimeo:"no",
57
		showScrubberWhenControllerIsHidden:"yes",
58
		showControllerWhenVideoIsStopped:"yes",
59
		showVolumeScrubber:"yes",
60
		showVolumeButton:"yes",
61
		showTime:"yes",
62
		showRewindButton:"yes",
63
		showQualityButton:"yes",
64
		showSubtitleButton:"yes",
65
		showShareButton:"yes",
66
		showDownloadButton:"yes",
67
		showMainScrubberToolTipLabel:"yes",
68
		showChromecastButton:"no",
69
		showFullScreenButton:"yes",
70
		repeatBackground:"yes",
71
		controllerHeight:41,
72
		controllerHideDelay:3,
73
		startSpaceBetweenButtons:7,
74
		spaceBetweenButtons:9,
75
		mainScrubberOffestTop:14,
76
		scrubbersOffsetWidth:4,
77
		timeOffsetLeftWidth:5,
78
		timeOffsetRightWidth:3,
79
		volumeScrubberWidth:80,
80
		volumeScrubberOffsetRightWidth:0,
81
		timeColor:"#777777",
82
		youtubeQualityButtonNormalColor:"#777777",
83
		youtubeQualityButtonSelectedColor:"#FFFFFF",
84
		scrubbersToolTipLabelBackgroundColor:"#FFFFFF",
85
		scrubbersToolTipLabelFontColor:"#5a5a5a",
86
		//redirect at video end

87
		redirectURL:"",
88
		redirectTarget:"_blank",
89
		//playback rate / speed

90
		showPlaybackRateButton:"yes",
91
		defaultPlaybackRate:"1", //0.25, 0.5, 1, 1.25, 1.5, 2

92
		//embed window

93
		embedWindowCloseButtonMargins:0,
94
		borderColor:"#333333",
95
		mainLabelsColor:"#FFFFFF",
96
		secondaryLabelsColor:"#a1a1a1",
97
		shareAndEmbedTextColor:"#5a5a5a",
98
		inputBackgroundColor:"#000000",
99
		inputColor:"#FFFFFF",
100
		//thumbnails preview

101
		thumbnailsPreview:"",
102
		thumbnailsPreviewWidth:196,
103
		thumbnailsPreviewHeight:110,
104
		thumbnailsPreviewBackgroundColor:"#000000",
105
		thumbnailsPreviewBorderColor:"#666",
106
		thumbnailsPreviewLabelBackgroundColor:"#666",
107
		thumbnailsPreviewLabelFontColor:"#FFF",
108
		// context menu

109
		showContextmenu:'yes',
110
		showScriptDeveloper:"yes",
111
		contextMenuBackgroundColor:"#1f1f1f",
112
		contextMenuBorderColor:"#1f1f1f",
113
		contextMenuSpacerColor:"#333",
114
		contextMenuItemNormalColor:"#888888",
115
		contextMenuItemSelectedColor:"#FFFFFF",
116
		contextMenuItemDisabledColor:"#444"
117
	});				
118
});
119
</script>

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 UIVideo Player UIVideo 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.

1
<ul id="vidAnnotations" style="display:none">
2
	<li data-start-time="00:00:01" data-end-time="00:00:05" data-left="600" data-top="100" data-normal-state-class="EVPAnnotationNormal">
3
		<p>The robin was declared Britain’s National Bird on December 15th, 1960.</p>
4
	</li>
5
	
6
	<li data-start-time="00:00:15" data-end-time="00:00:20" data-left="40" data-top="400" data-show-close-button="yes" data-click-source="https://en.wikipedia.org/wiki/European_robin" data-click-source-target="_blank" data-normal-state-class="EVPAnnotationLinkNormal">
7
		<p>You can learn more about this bird on the Wikipedia page about <strong>European Robins</strong>.</p>
8
	</li>	
9
</ul>

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.

1
annotiationsListId:"vidAnnotations",
2
showAnnotationsPositionTool:"no",

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

Video Player AnnotationsVideo Player AnnotationsVideo 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.

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.