Music Player In JavaScript With Source Code
The Music Player In JavaScript is developed using JavaScript, CSS, bootstrap, and HTML. This Project With Source Code is for listening to our self-made songs collection app. The user can play different kinds of music and enjoy the sound of their music. The user can adjust the background color of the app and click the forward and backward play button to change the songs.
A JavaScript Music Player user can listen to their music and relax by enjoying the music sound as their choice like the music player. This project includes a lot of JavaScript for making the functioning of the project.
This Music Player JavaScript also includes a downloadable Music Player JavaScript Code for free, just find the downloadable source code below and click to start downloading.
Watch the video here to see the full running Music Player in Javascript with Source Code.
I have here a suggested list of Best JavaScript Projects with Source Code Free to download and I’m sure this can help you to improve your skills in JavaScript programming and web development as a whole.
To start creating a Music Player In JavaScript, makes sure that you have any platform in creating a JavaScript, CSS, bootstrap, and HTML installed in your computer, in my case I will use Sublime Text.
Steps on how to create a Music Player In JavaScript
Music Player In JavaScript With Source Code
- Step 1: Open Sublime Text.
First after installing sublime text IDE, click “open” to start.
- Step 2: Create a HTML file.
Second click “file” and select “save as” and named it “index.html“
- Step 3: Create a CSS file.
Third click “file” and select “save as” and named it “app.css“
- Step 4: Create a JavaScript file.
Fourth click “file” and select “save as” and named it “app.js“
- Step 5: The actual code.
You are free to copy the code given below and paste to your different file created.
The Code Given Below Is For The Index.html Module
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 |
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="UTF-8"> <title>Audio Player</title> <link href="https://fonts.googleapis.com/css?family=Darker+Grotesque|Poiret+One&display=swap" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" type="text/css" href="src/app.css"> </head> <body> <div class="audio-player" id="skin"> <div class="user_avatar"> <span class="live"> live <i class="fa fa-circle fa-fw"></i> </span> <span class="listeners"> 23 <i class="fa fa-microphone fa-fw"></i> </span> <img src="assets/avatar.jpeg"> <nav class="set"> <a class="dropdown-toggle" href="#" title="Menu"><i class="fa fa-cogs"></i></a> <ul class="dropdown"> <li><a href="#" id="darkButton">Dark</a></li> <li><a href="#" id="whiteButton">Default</a></li> <li><a href="#" id="blueButton">Blue</a></li> </ul> </nav> </div> <div class="holder"> <div class="cover"> <img src="assets/cover.jpg"> </div> <div class="audio-wrapper" id="player-container" href="javascript:;"> <audio id="player" preload="metadata" onloadedmetadata="mDur()" ontimeupdate="initProgressBar()"> <source src="" type="audio/mp3"> </audio> </div> <div class="player-controls scrubber"> <div> <div> <p class="title"></p> </div> <div class="range"> <input id="dur" type="range" class="range" name="rng" min="0" max="1" step="0.00000001" value="0" onchange="mSet()" style="width: 100%"> </div> <br> <span class="time start-time"></span> <span class="time end-time"></span> <br> <div class="ctrl"> <div> <a href="#prev" class="ctrl_btn " id="prev"><i class="fa fa-arrow-left" ></i></a> <span id="play-btn" class="fa fa-play "></span> <a href="#next" class="ctrl_btn " id="next"><i class="fa fa-arrow-right" ></i></a> </div> <div class="volumeControl"> <div class="wrapper"> <i class="fa fa-volume-up"></i> <span class="outer"> <span class="inner"></span> </span> </div> </div> </div> </div> <div> </div> </div> </div> <div class="action"> <div> <a href="#" class="like shadow">Like <i class="fa fa-heart-o"></i></a> <a href="#" class="like shadow">Share <i class="fa fa-share-alt"></i></a> <a href="#" class="like shadow">Subscribe <i class="fa fa-podcast"></i></a> </div> </div> </div> <script type="text/javascript" src="assets/jquery/jquery.min.js"></script> <script type="text/javascript" src="src/app.js"></script> </body> </html> |
In this module which is the html file of the system.
The Code Given Below Is For The App.css Module
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
* { transition: 0.8s ease !important; } html { height: 100%; display: table; margin: auto; } body { height: 100%; display: table-cell; vertical-align: middle; background: #f1f1f1; font-family: 'Poiret One', cursive; } a { color: #fff; text-decoration: none; } .holder { margin: 0.23rem 0 0.23rem 0; display: flex; align-items: center; } .shadow { box-shadow: 0 1px 30px rgba(0, 0, 0, 0.22); } /* Important stuff */ .set { position: absolute; right: 1em; top: 0; z-index: 999; } .dropdown-toggle { display: block; width: 50%; margin: 0 auto; } .dropdown-toggle i { padding: 0.5em 0.55em; background: #fff; border-radius: 4px; color: #555; } #skin.dark { background: #334d50; /* fallback for old browsers */ background: -webkit-linear-gradient(to right, #cbcaa5, #334d50); /* Chrome 10-25, Safari 5.1-6 */ background: linear-gradient(to right, #cbcaa5, #334d50); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ color: #fff!important; border-color: #fff!important; } #skin.white { background: white; } #skin.blue { background: linear-gradient(126deg, rgba(43, 57, 144, 1), rgba(102, 45, 145, 0.9)); } ul.dropdown { display: none; position: absolute; left: 25%; width: 50%; margin-top: 0.5em; margin: 0.5em auto; background: #777; min-width: 12em; padding: 0; border-radius: 0 0 0.2em 0.2em; } ul.dropdown li { list-style-type: none; } ul.dropdown li a { text-decoration: none; padding: 0.5em 1em; display: block; } .audio-player { position: relative; border: 1px solid #dfdfdf; width: 50vw; margin: 1rem auto; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32); background: #fff; padding: 1rem; height: auto; } .audio-player .user_avatar { width: 100%; justify-content: space-around; margin: 0 auto; position: relative; } .audio-player .user_avatar .live, .audio-player .user_avatar .listeners { background: #fff; padding: 8px 10px 0 10px; font-size: 15px; font-weight: 700; color: #555 !important; border-radius: 4px; margin: 3px; text-align: center; } .live i { -moz-animation-duration: 1s; -moz-animation-name: blink; -moz-animation-iteration-count: infinite; -moz-animation-direction: alternate; -webkit-animation-duration: 1s; -webkit-animation-name: blink; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; animation-duration: 1s; animation-name: blink; animation-iteration-count: infinite; animation-direction: alternate; color: red; } @-moz-keyframes blink { from { opacity: 1; } to { opacity: 0; } } @-webkit-keyframes blink { from { opacity: 1; } to { opacity: 0; } } @keyframes blink { from { opacity: 1; } to { opacity: 0; } } .audio-player .user_avatar img { display: block; margin: 0 auto; height: 100px; width: 100px; padding: 0.65em; object-fit: cover; border-radius: 50%; border: 2px solid #dfdfdf; background: #fff; margin-top: -4em; } #dur:hover { cursor: pointer; } .audio-player .cover img { height: 200px; width: 200px; object-fit: cover; border-radius: 30px; padding: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); } .audio-player .title { padding: 0; margin-top: 2.5rem; font-weight: 800; font-size: 28px; } .audio-player .like { padding: 6px 17px; background: #fff; font-size: 16px; color: #555; margin: 1rem 0; font-weight: 900; text-decoration: none; position: relative; } .audio-player .player-controls { align-items: center; justify-content: center; flex: 4; position: relative; padding: 0 1rem; margin: 0 auto; } .audio-player .player-controls p { color: #000; } .progress_bar { border: 2px solid #ccc; width: 100%; min-height: 15px; display: flex; padding: 0.45em 0; align-items: center; } .range { position: relative; } .range input[type=range] { appearance: none; padding: 0; width: 100%; height: 22px; cursor: pointer; display: block; } .range input[type=range]:focus { outline: none; } .range input[type=range][disabled] { opacity: 0.3; cursor: default; background: transparent; } .range .rangeslider { position: relative; height: 22px; cursor: pointer; user-select: none; } .range .rangeslider:before { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; content: ""; position: absolute; top: 50%; transform: translateY(-50%); } .range input::-webkit-slider-runnable-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; margin: 11px 0; } .range input::-moz-range-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; margin: 11px 0; } .range input::-ms-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; color: transparent; padding: 11px 0; background: transparent; border-color: transparent; } .range input::-ms-fill-lower, .range input::-ms-fill-upper { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; } .range input::-ms-fill-lower { background: #60cd18; } .range .rangeslider-fill-lower { background-color: #60cd18; border-radius: 100px; position: absolute; top: 50%; transform: translateY(-50%); height: 4px; will-change: width; } .range input::-webkit-slider-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, .5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; appearance: none; transform: translateY(-50%); margin-top: 2px; } .range input::-moz-range-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, .5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; } .range input::-ms-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, .5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; } .range .rangeslider-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, .5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 50%; background: #333940; cursor: pointer; position: absolute; touch-action: pan-x; top: 50%; transform: translateY(-50%); will-change: left; } .audio-player #play-btn, .ctrl_btn { margin: 0 1rem 2rem 0; color: #363732; } .audio-player #play-btn { padding: 1rem 1.2rem; font-size: 24px; } .audio-player .ctrl_btn { font-size: 22px; } .audio-player #play-btn:hover { cursor: pointer; } .audio-player .volumeControl { display: flex; flex-basis: 20%; justify-content: center; align-items: center; padding-bottom: 1rem; } .audio-player .volumeControl .wrapper { display: flex; flex-basis: 100%; align-items: center; color: #363732; } .audio-player .volumeControl .wrapper:hover i.fa { color: #363732; } .audio-player .volumeControl .outer { border-radius: 2px; box-shadow: -2px 3px 4px rgba(0, 0, 0, 0.23); overflow: hidden; height: 0.3rem; flex-basis: 80%; margin-left: 0.4rem; display: flex; justify-content: flex-start; align-items: center; } .audio-player .volumeControl .outer .inner { background-color: #363732; width: 100%; display: inline-block; height: 100%; } .audio-player .volumeControl .outer:hover { cursor: pointer; } .start-time, .end-time { font-size: 14px; font-weight: 800; font-family: 'Darker Grotesque', sans-serif; transition: 1s ease-in-out; line-height: 0; } .start-time { float: left; position: relative; left: 0; } .end-time { float: right; position: relative; right: 0; } .ctrl { display: flex; justify-content: space-between; } .action { margin: 1rem auto; text-align: left; } .action span { font-size: 14px; font-family: 'Darker Grotesque', sans-serif; } @media screen and (max-width: 950px) { ul.dropdown { right: 20%; left: unset; } .holder { display: block; justify-content: all; align-items: all; } .audio-player { width: 80%; padding: 1rem 1rem; } .audio-player .cover img { height: 100%; width: 80%; object-fit: cover; display: block; margin: 0 auto; } .audio-player .player-controls { position: relative; padding: 0 0; margin: 0 auto; } .audio-player #play-btn, .ctrl_btn { margin: 15px 6px; } .audio-player .volumeControl, .audio-player .volumeControl .wrapper { display: block; } .audio-player .volumeControl .wrapper .fa-volume-up { margin: 10px; opacity: 0.6; } .audio-player .title { text-align: center; } .start-time { left: 0.85em; } .end-time { right: 1em; } .ctrl, .action { display: block; text-align: center; } .action a { display: block; } .set { position: relative; } .audio-player .user_avatar { margin: 0 0 1em 0; display: flex; justify-content: space-around; } .audio-player .user_avatar img { display: none; } } |
In this module which is the css file of the system.
The Code Given Below Is For The App.js Module
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 |
let playlist = [ { 'title': 'Disco Mix', 'audio': "assets/sample1.mp3", }, { 'title': 'I Remember You By Jude Suarez', 'audio': "assets/sample2.mp3", } ]; i = 0; n = playlist.length; let player = document.getElementById( 'player' ); let dur = document.getElementById( 'dur' ); playlist.forEach( function( i ) { console.log( i.audio ) player.src = i.audio; $( '.title' ).html( i.title ); }, ); function calculateTotalValue( length ) { let minutes = Math.floor( length / 60 ), seconds_int = length - minutes * 60, seconds_str = seconds_int.toString( ), seconds = seconds_str.substr( 0, 2 ), time = minutes + ':' + seconds return time; } function calculateCurrentValue( currentTime ) { let current_hour = parseInt( currentTime / 3600 ) % 24, current_minute = parseInt( currentTime / 60 ) % 60, current_seconds_long = currentTime % 60, current_seconds = current_seconds_long.toFixed( ), current_time = ( current_minute < 10 ? "0" + current_minute : current_minute ) + ":" + ( current_seconds < 10 ? "0" + current_seconds : current_seconds ); return current_time; } function initProgressBar( ) { let length = player.duration; let current_time = player.currentTime; let totalLength = calculateTotalValue( length ) jQuery( ".end-time" ).html( totalLength ); let currentTime = calculateCurrentValue( current_time ); jQuery( ".start-time" ).html( currentTime ); dur.value = player.currentTime; if ( player.currentTime == player.duration ) { $( "#play-btn" ).fadeIn( "slow", function( ) { $( this ).removeClass( "fa-pause" ); $( this ).addClass( "fa-play" ); dur.value = 0; } ); } }; function mSet( ) { player.currentTime = dur.value; } function mDur( ) { let length = player.duration; dur.max = length; } function initPlayers( num ) { for ( let i = 0; i < num; i++ ) { ( function( ) { let playerContainer = document.getElementById( 'player-container' ), player = document.getElementById( 'player' ), isPlaying = false, playBtn = document.getElementById( 'play-btn' ); if ( playBtn != null ) { playBtn.addEventListener( 'click', function( ) { togglePlay( ) } ); } function togglePlay( ) { if ( player.paused === false ) { player.pause( ); isPlaying = false; $( "#play-btn" ).fadeIn( "slow", function( ) { $( this ).removeClass( "fa-pause" ); $( this ).addClass( "fa-play" ); } ); } else { player.play( ); $( "#play-btn" ).fadeIn( "slow", function( ) { $( this ).removeClass( "fa-play" ); $( this ).addClass( "fa-pause" ); } ); isPlaying = true; } } }( ) ); } } $( "#next" ).data( 'dir', 1 ); $( "#prev" ).data( 'dir', -1 ); $( '#next, #prev' ).on( 'click', function( ) { i = ( i + $( this ).data( 'dir' ) + n ) % n; console.log( i ); player.src = playlist[ i ].audio; $( '.title' ).html( playlist[ i ].title ); $( '#play-btn' ).removeClass( "fa-play" ); $( '#play-btn' ).addClass( "fa-pause" ); player.play( ); } ); $( ".audio-player" ) .toArray( ) .forEach( function( player ) { let audio = $( player ).find( "audio" )[ 0 ]; let volumeControl = $( player ).find( ".volumeControl .wrapper" ); volumeControl.find( ".outer" ).on( "click", function( e ) { let volumePosition = e.pageX - $( this ).offset( ).left; let audioVolume = volumePosition / $( this ).width( ); if ( audioVolume >= 0 && audioVolume <= 1 ) { audio.volume = audioVolume; $( this ) .find( ".inner" ) .css( "width", audioVolume * 100 + "%" ); } } ); } ); $( function( ) { // Dropdown toggle $( '.dropdown-toggle' ).click( function( ) { $( this ).next( '.dropdown' ).slideToggle( "fast" ); } ); $( document ).click( function( e ) { var target = e.target; if ( !$( target ).is( '.dropdown-toggle' ) && !$( target ).parents( ).is( '.dropdown-toggle' ) ) { $( '.dropdown' ).hide( ); } } ); } ); $( '#darkButton' ).click( switchDark ); $( '#whiteButton' ).click( switchWhite ); $( '#blueButton' ).click( switchBlue ); function switchDark( ) { $( '#skin' ).attr( 'class', 'dark audio-player' ); $( '.inner' ).css( 'background', '#fff' ); $( '.title' ).css( 'color', '#fff' ); $( '.time' ).css( 'color', '#fff' ); $( '.fa-volume-up' ).css( { 'color': '#fff' } ); $( '.audio-player #play-btn' ).css( { 'color': '#fff', 'border-color': '#fff' } ); $( '.ctrl_btn' ).css( { 'color': '#fff', 'border-color': '#fff' } ); } function switchWhite( ) { $( '#skin' ).attr( 'class', 'white audio-player' ); $( '.inner' ).css( 'background', '#555' ); $( '.title' ).css( 'color', '#555' ); $( '.time' ).css( 'color', '#555' ); $( '.fa-volume-up' ).css( { 'color': '#555' } ); $( '.audio-player #play-btn' ).css( { 'color': '#555', 'border-color': '#555' } ); $( '.ctrl_btn' ).css( { 'color': '#555', 'border-color': '#555' } ); } function switchBlue( ) { $( '#skin' ).attr( 'class', 'blue audio-player' ); $( '.inner' ).css( 'background', '#fff' ); $( '.title' ).css( 'color', '#fff' ); $( '.time' ).css( 'color', '#fff' ); $( '.fa-volume-up' ).css( { 'color': '#fff' } ); $( '.audio-player #play-btn' ).css( { 'color': '#fff', 'border-color': '#fff' } ); $( '.ctrl_btn' ).css( { 'color': '#fff', 'border-color': '#fff' } ); } initPlayers( jQuery( '#player-container' ).length ); |
In this module which is the javascript file of the system.
Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code
Summary
This JavaScript Project With Source Code is simply in HTML, CSS, and JavaScript. Taking about the features of this system, the user can listen to their music and relax by enjoying the music sound as their choice like the music player. Also, you can adjust the background color of the app. You just have to click on settings option and set the color they like. This project includes a lot of javascript for making the functioning of the project.
Related Articles
- Todo List In JavaScript With Source Code
- Currency Converter Project in JavaScript with Source Code
- Calculator In JavaScript Source Code
- Fibonacci Series In JavaScript With Source Code
Inquiries
If you have any questions or suggestions about Music Player In JavaScript , please feel free to leave a comment below.