How we can create a video player for showing a video on websites? Solution: See this Video Player For Website Using HTML CSS jQuery, HTML5 Video Player.
Previously I have shared an advance video player with a playlist feature, this is a simple and minimal video player for website. Basically, HTML5 comes with a specific video tag ( <video src=""> ) for showing video on website without flash. But the by default video tag‘s style is not impressive, but we can customize that and create an attractive video player. With jQuery, we can change all the icons, buttons, features, etc.
Today you will learn to create HTML5 Video Player with minimal design. Basically, there is a header and a video player box. The video player contains all custom SVG buttons like play, pause, volume, full screen, etc. There is an overlay effect at start and when you will stop or pause the video then the overlay will appear again. At the end of the video, there is a replay button to start the video over again. Also, you can mute and turn on the sound by clicking the sound icon, there is a toggle feature.
So, Today I am sharing Video Player For Website Using HTML CSS jQuery. There I have used jQuery for full customization and functions, used CSS for styling, and I have used SVG shapes as a background image for all the icons. In this video player, everything is changed or customized, you can see a flat and minimal design. You can use this program on your website to show videos to users.
If you are thinking now how this HTML 5 video player actually is, then see the preview given below.
Preview Of HTML5 Video Tag Customization
See this video preview to getting an idea of how this video player looks like.
Now you can see this visually, also you can see the program live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- Material Button With Ripple Click Effect
- Drag Date Range Selector
- Scrolling Sub Menu Items
- Parallax Draggable Slider
Video Player For Website Using HTML CSS jQuery Source Code
Before sharing source code, let’s talk about it. First I have created a header section to put the heading line for this program. After that, I have created the main div for the whole program with ID name “videoContainer” and placed all elements inside it. There I have created a button to play and pause feature, used HTML video tag to place the video, and many divs for all the icons and elements. Also in the HTML file, I have linked all other files like CSS, JS, and jQuery CDN.
Now using CSS I have placed all the elements in the right place, as you can see in the preview. With CSS first I have simply given basic values to elements like size, position, margin, padding, color, etc. There I have used CSS @media query to create this program with responsive design. I have placed icons with SVG shapes as background-image
jQuery handling here all the features in this program. First, jQuery fetched and stored all the elements in variables using $('#ID') method. There also used toggle feature using .toggleClass command to some places like play/pause and sound/mute etc. For creating functions according to user actions used if{} else{} statements and declare what to do, the icons are also changing. jQuery modifying CSS values like show and hide and changing images dynamically.
Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating the program you have to create 3 files. First file for HTML, second for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>Video Player For Website | Webdevtrick.com</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800"> <link rel="stylesheet" href="./style.css"> </head> <body> <header> <div class="container"> <h1> <span>Html, CSS, jQuery</span> <span>Video</span> <span>Player</span> </h1> </div> </header> <div id="videoContainer"> <div class="overlay"> <div class="button"></div> </div> <div id="video"> <video src="https://webdevtrick.com/wp-content/uploads/sample-footage.mp4"> </video> </div> <div id="controls"> <div class="playButton"> <div class="playPause"></div> </div> <div class="ProgressContainer"> <div class="timer intialTime"> 00:00 </div> <div class="progressBar"> <div class="progress"></div> </div> <div class="time"> 00:00 </div> <div class="timer fullTime"> 00:00 </div> </div> <div class="volume"> <div class="icon"></div> <div class="intensityBar"> <div class="intensity"></div> </div> </div> <div class="scale"> <div class="icon"></div> </div> </div> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ *, *::before, *::after { box-sizing: border-box; outline: none; } body { margin: 0; padding: 0; background: #eee; position: relative; } a, a:hover, a:focus { display: inline-block; text-decoration: none; color: #fff; } h1, h2, h3, h4, h5, h6, p, a, li, button { margin: 5px 0; font-family: "Open Sans", sans-serif; } ul, ol { list-style: none; padding: 0; margin: 0; } button { background: none; border: none; } .container { width: 100%; padding: 0 40px; max-width: 1300px; margin: 0 auto; clear: both; } .container::after { content: ""; display: block; clear: both; } body::-webkit-scrollbar { width: 4px; } body::-webkit-scrollbar-thumb { background-color: #555; } body { min-height: 100vh; } .container { width: 80%; margin: 0 auto; } @media (max-width: 768px) { .container { width: 100%; } } header { padding: 20px 0; text-align: center; } header h1 { font-size: 50px; font-weight: 700; color: #39a072; } @media (max-width: 768px) { header h1 { font-size: 30px; } } @media (max-width: 480px) { header h1 { font-size: 25px; } } header h1 span:first-of-type { font-size: 25px; font-weight: 300; color: #222; } header h1 span:last-of-type { font-size: 25px; font-weight: 300; color: #222; } header p { font-size: 14px; font-weight: 400; color: #666; line-height: 1.6em; margin-top: 10px; } #videoContainer { width: 70vw; height: 65vh; background: #39a072; margin: 30px auto; border-radius: 5px; box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2); margin-bottom: 20px; position: relative; overflow: hidden; -webkit-user-select: none; -moz-user-select: none; user-select: none; } #videoContainer.fullScreen { width: 100vw !important; height: 100vh !important; } #videoContainer.small .intensityBar { width: 50px !important; } #videoContainer.small .playButton { margin: 0 !important; margin-right: 5px !important; } #videoContainer.small .timer { display: none !important; } #videoContainer.small .playPause, #videoContainer.small .volume .icon, #videoContainer.small .scale .icon { width: 15px !important; height: 15px !important; } #videoContainer.small .progressBar { height: 6px !important; } #videoContainer.small .overlay .button { width: 50px !important; height: 50px !important; } #videoContainer.small .time { display: none !important; } #videoContainer .overlay { width: 100%; height: 100%; background: radial-gradient(circle, rgba(77, 191, 140, 0.9), rgba(41, 115, 82, 0.9)); position: absolute; top: 0; left: 0; z-index: 999; border-radius: 5px; } #videoContainer .overlay .button { width: 80px; height: 80px; position: absolute; top: 50%; left: 50%; background: url(https://webdevtrick.com/wp-content/uploads/playBTN.svg); background-size: 100% 100%; transform: translate(-50%, calc(-50% - 30px)); cursor: pointer; transition: width 0.2s, height 0.2s; } #videoContainer .overlay .button:hover { width: 90px; height: 90px; } #videoContainer #video { width: 100%; height: calc(100% - 60px); position: relative; top: 0; left: 0; overflow: hidden; border-radius: 5px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; } #videoContainer #video video { width: 100%; height: 100%; position: absolute; top: 0; left: 0; border-radius: 5px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } #videoContainer #video video::-webkit-media-controls-enclosure { display: none !important; } #videoContainer #controls { width: 100%; height: 60px; background: #4dbf8c; position: absolute; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; z-index: 2147483647; } #videoContainer #controls.is-visible { transform: translateY(0); } #videoContainer #controls .playButton { width: 70px; height: 100%; background: #4dbf8c; display: flex; align-items: center; justify-content: center; margin-right: 20px; cursor: pointer; transition: all 0.4s; border-bottom-left-radius: 5px; } #videoContainer #controls .playButton:hover { background: #41b682; } #videoContainer #controls .playButton .playPause { width: 25px; height: 25px; background: url(https://webdevtrick.com/wp-content/uploads/play.svg); background-size: 100% 100%; } #videoContainer #controls .ProgressContainer { color: #fff; width: calc(100% - 100px); height: 100%; display: flex; align-items: center; justify-content: flex-start; position: relative; } #videoContainer #controls .ProgressContainer .progressBar { width: 100%; height: 8px; background: #39a072; border-radius: 20px; cursor: pointer; overflow: hidden; } #videoContainer #controls .ProgressContainer .progressBar:hover + .time { opacity: 1; transform: translateY(0); } #videoContainer #controls .ProgressContainer .progressBar .progress { width: 0%; height: 100%; background: #fff; border-radius: 20px; } #videoContainer #controls .ProgressContainer .timer { margin: 0 10px; font-family: Arial, sans-serif; font-weight: 300; font-size: 12px; font-weight: 300; color: #2c7a57; letter-spacing: 1px; } #videoContainer #controls .ProgressContainer .time { width: 80px; height: 25px; background: #2c7a57; position: absolute; top: -20px; left: 0; border-radius: 5px; color: #fff; font-family: Arial, sans-serif; text-align: center; line-height: 25px; font-size: 12px; letter-spacing: 1px; opacity: 0; transform: translateY(10px); transition: transform 0.3s, opacity 0.3s; } #videoContainer #controls .ProgressContainer .time::after { content: ""; display: block; width: 0; height: 0; position: absolute; top: 25px; left: 33px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 6px solid #2c7a57; } #videoContainer #controls .volume { width: 150px; height: 100%; display: flex; align-items: center; justify-content: flex-end; position: relative; } #videoContainer #controls .volume .icon { width: 25px; height: 25px; background: url(https://webdevtrick.com/wp-content/uploads/volume.svg); background-size: 100% 100%; cursor: pointer; margin-right: 10px; } #videoContainer #controls .volume .intensityBar { width: 100px; height: 4px; background: #39a072; border-radius: 20px; max-width: 100px; overflow: hidden; transform-origin: right center; cursor: pointer; transition: all 0.5s; } #videoContainer #controls .volume .intensityBar .intensity { width: 50%; height: 100%; background: #fff; } #videoContainer #controls .scale { width: 70px; height: 100%; background: #4dbf8c; display: flex; align-items: center; justify-content: center; margin-left: 5px; cursor: pointer; transition: all 0.4s; border-bottom-right-radius: 5px; } #videoContainer #controls .scale:hover { background: #40b27f; } #videoContainer #controls .scale .icon { width: 25px; height: 25px; background-size: 100% 100%; background: url(https://webdevtrick.com/wp-content/uploads/expand.svg); background-size: 100% 100%; } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
// Code By Webdevtrick ( https://webdevtrick.com ) $(document).ready(function () { 'use strict'; var play_pause = $('.playButton'), container = $('#videoContainer'), playIcon = $('.playButton .playPause'), video = $('video'), play = $('.play'), volume = $('.volume .icon'), volumeIntesity = $('.volume .intensityBar'), intensity = $('.intensity'), progressBar = $('.progressBar'), progress = $('.progressBar .progress'), timer = $('.intialTime'), vidDuration = $('.fullTime'), expandButton = $('.scale'), overlayScreen = $('.overlay'), timeState = $('.time'), overlayButton = $('.overlay .button'), update; $(window).resize(function () { resizeVid(); }); resizeVid(); updateplayer(); play_pause.add(video).click(function () { playVid(); }); progressBar.click(function () {skip(); }); progressBar.mousemove(function () { timeState.text(getTimeState()); }); volume.click(function () { toggleMute(); }); expandButton.click(function () { $(this).toggleClass('active'); if ($(this).hasClass('active')) { $('#controls').addClass('is-visible'); fullScreen(); } else { $('#controls').removeClass('is-visible'); exitTheFullScreen(); } }); volumeIntesity.click(function () { changeVolume(); }); overlayButton.click(function () { playVid();}); vidDuration.text(getFormatedFullTime()); function playVid() { if (video.get(0).paused) { video.get(0).play(); playIcon.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/pause.svg)', 'background-size': '100% 100%' }); overlayScreen.hide(); update = setInterval(updateplayer, 1); } else { video.get(0).pause(); playIcon.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/play.svg)', 'background-size': '100% 100%' }); overlayScreen.show(); clearInterval(update); } } function updateplayer() { var percentage = (video[0].currentTime / video[0].duration) * 100; progress.css({'width': percentage + '%'}); timer.text(getFormatedTime()); vidDuration.text(getFormatedFullTime()); if (video[0].ended) { playIcon.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/play.svg)', 'background-size': '100% 100%' }); overlayScreen.show(); overlayButton.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/replay.svg)', 'background-size': '100% 100%' }); } else if (video[0].paused) { overlayButton.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/playBTN.svg)', 'background-size': '100% 100%' }); } } function getTimeState() { var mouseX = event.pageX - progressBar.offset().left, width = progressBar.outerWidth(); var currentSeconeds = Math.round((mouseX / width) * video[0].duration); var currentMinutes = Math.floor(currentSeconeds/60); if (currentMinutes > 0) { currentSeconeds -= currentMinutes * 60; } if (currentSeconeds.toString().length === 1) { currentSeconeds = "0" + currentSeconeds; } if (currentMinutes.toString().length === 1) { currentMinutes = "0" + currentMinutes; } timeState.css('left', (mouseX / width) * progressBar.width() + 18 + 'px'); return currentMinutes + ':' + currentSeconeds; } function skip() { var mouseX = event.pageX - progressBar.offset().left, width = progressBar.outerWidth(); video[0].currentTime = (mouseX / width) * video[0].duration; updateplayer(); } function getFormatedFullTime() { var totalSeconeds = Math.round(video[0].duration); var totalMinutes = Math.floor(totalSeconeds/60); if (totalMinutes > 0) { totalSeconeds -= totalMinutes * 60; } if (totalSeconeds.toString().length === 1) { totalSeconeds = "0" + totalSeconeds; } if (totalMinutes.toString().length === 1) { totalMinutes = "0" + totalMinutes; } return totalMinutes + ':' + totalSeconeds; } function getFormatedTime() { var seconeds = Math.round(video[0].currentTime); var minutes = Math.floor(seconeds / 60); if (minutes > 0) { seconeds -= minutes * 60; } if (seconeds.toString().length === 1) { seconeds = "0" + seconeds; } if (minutes.toString().length === 1) { minutes = "0" + minutes; } return minutes + ':' + seconeds; } function toggleMute() { if (!video[0].muted) { video[0].muted = true; volume.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/mute.svg)', 'background-size': '100% 100%' }); intensity.hide(); } else { video[0].muted = false; volume.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/volume.svg)', 'background-size': '100% 100%' }); intensity.show(); } } function changeVolume() { var mouseX = event.pageX - volumeIntesity.offset().left, width = volumeIntesity.outerWidth(); video[0].volume = (mouseX / width); intensity.css('width', (mouseX / width) * width + 'px'); video[0].muted = false; volume.css({ 'background': 'url(https://webdevtrick.com/wp-content/uploads/volume.svg)', 'background-size': '100% 100%' }); intensity.show(); } function fullScreen() { if (video[0].requestFullscreen) { video[0].requestFullscreen(); } else if (video[0].webkitRequestFullscreen) { video[0].webkitRequestFullscreen(); } else if (video[0].mozRequestFullscreen) { video[0].mozRequestFullscreen(); } else if (video[0].msRequestFullscreen) { video[0].msRequestFullscreen(); } else { video.dblclick(function () { fullScreen(); }); } } function exitTheFullScreen() { if (document.webkitExitFullscreen()) { document.webkitExitFullscreen(); } else if (document.mozCancelFullScreen()) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen()) { document.msExitFullscreen(); } else { video.dblclick(function () { fullScreen(); }); } } function resizeVid() { if (container.width() < 600) { container.addClass('small'); } else { container.removeClass('small'); } } $(window).keypress(function (e) { if (e.keyCode === 0 || e.keyCode === 32) { e.preventDefault() playVid(); } }); for (var i = 0, l = videos.length; i < l; i++) { var video = videos[i]; var src = video.src || (function () { var sources = video.querySelectorAll("source"); for (var j = 0, sl = sources.length; j < sl; j++) { var source = sources[j]; var type = source.type; var isMp4 = type.indexOf("mp4") != -1; if (isMp4) return source.src; } return null; })(); if (src) { var isYoutube = src && src.match(/(?:youtu|youtube)(?:\.com|\.be)\/([\w\W]+)/i); if (isYoutube) { var id = isYoutube[1].match(/watch\?v=|[\w\W]+/gi); id = (id.length > 1) ? id.splice(1) : id; id = id.toString(); var mp4url = "http://www.youtubeinmp4.com/redirect.php?video="; video.src = mp4url + id; } } } }); |
That’s It. Now you have successfully created Video Player For Website Using HTML CSS jQuery, HTML5 Video Player. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.