Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Tutorial How to make A simple audio player in HTML, JavaScript, CSS.

Today I am going to teach you how to make A simple Audio Player in HTML 5, JavaScript, and CSS. To follow this tutorial be sure to download notepad++ being as it is mostly used in HTML, JavaScript, and CSS. Let's begin to start this we will need 3 important files to make 1. HTML (player.html), 2. JavaScript (player.js), 3. CSS (player.css). After we have created our 3 main important items, we need to create 2 folders inside the folder you added your main important classes, 1. Audio, 2. Textures. After that we add our music(sounds) and textures(play button, stop button, pause button, replay button, volume icon(button / image), background). After that we type in the following code in the HTML file
[CODE lang="html" title="HTML Class File" highlight="1,1-21"]<html>
<head>
<script type="text/javascript" src="player.js"></script>
<link rel="stylesheet" type="text/css" href="player.css">
</head>
<body>
<div id="wrapper">
<div id='player'>
<audio id="music_player">
<source src="Audio/Your_Audio.mp3"/>
</audio>
<input type="image" src="Textures/play.png" onclick="play_aud()" id="play_button">
<input type="image" src="Textures/pause.png" onclick="pause_aud()" id="play_button">
<input type="image" src="Textures/stop.png" onclick="stop_aud()" id="play_button">
<input type="image" src="Textures/replay.png" onclick="replay_aud()" id="play_button">
<img src="Textures/volume.png" id="vol_img">
<input type="range" id="change_vol" onchange="change_vol()" step="0.05" min="0" max="1" value="1">
</div>
</div>
</body>
</html>[/CODE]

Now we type in the following code for the CSS file

[CODE lang="css" title="CSS Class File" highlight="1,1-38"]body
{
width:100%;
margin:0 auto;
padding:0px;
font-family:helvetica;
background-color:#00000F;
}
#wrapper
{
text-align:center;
margin:0 auto;
padding:50px;
width:995px;
}

#player
{
background-color:#4CBB17;
width:400px;
margin-left:300px;
padding:5px;
box-sizing:border-box;
background:url(Textures/background.png);
}
input[type="image"]
{
float:left;
height:20px;
margin-left:2px;
margin-right:5px;
margin-top:2px;
}
#vol_img
{
margin-left:150px;
width:20px;
}[/CODE]

Now we enter the following code for the JavaScript file

[CODE lang="javascript" title="JavaScript Class File" highlight="1,1-30"]document.addEventListener("DOMContentLoaded", function() { startplayer(); }, false);
var player;

function startplayer()
{
player = document.getElementById('music_player');
player.controls = false;
}

function play_aud()
{
player.play();
}
function pause_aud()
{
player.pause();
}
function stop_aud()
{
player.pause();
player.currentTime = 0;
}
function replay_aud()
{
player.loop = true;
}
function change_vol()
{
player.volume=document.getElementById("change_vol").value;
}[/CODE]

Download the zipped Project here containing all the tutorial files.
Tutorial Project

NEW! Updated Tutorial Project! Added in A few big major adjustments and some pretty cool features. See the updated Tutorial Project here! Updated Tutorial Project
 
Last edited:
To round the player in the css file simply just copy this
[CODE lang="css" title="How To Round Your Audio Player's Player Box" highlight="1,1-12"]-webkit-border-top-right-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-radius-bottomright: 5px;
border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-left-radius: 5px;
-webkit-border-top-left-radius: 5px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;[/CODE]
and put it under
[CODE lang="css" title="Result" highlight="9"]#player
{
background-color:#4CBB17;
width:400px;
margin-left:300px;
padding:5px;
box-sizing:border-box;
background:url(Textures/background.png);

}[/CODE]

40
 
Sure thing in the #player section of the css go to the bg(background.png - Image), add the /* to filter out the lines of the unwanted code, then in the css on the #player constructor add this.
[CODE lang="css" title="Gradient + Shadowing + Opacity" highlight="1,1-15"]-webkit-box-shadow: 0px 0px 13px rgba(0,0,0,.3),inset 0 1px 0px rgba(255,255,255,.2);
-moz-box-shadow: 0px 0px 13px rgba(0,0,0,.3),inset 0 1px 0px rgba(255,255,255,.2);
box-shadow: 0px 0px 13px rgba(0,0,0,.3),inset 0 1px 0px rgba(255,255,255,.2);
border: bold white;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
opacity: 1;
-webkit-box-shadow: inset 0 1px 0px rgba(255,255,255,.2);
-moz-box-shadow: inset 0 1px 0px rgba(255,255,255,.2);
box-shadow: inset 0 1px 0px rgba(255,255,255,.2);
background: #f5f6f6; /* Old browsers */
background: -moz-linear-gradient(top, #f5f6f6 0%, #dbdce2 21%, #b8bac6 49%, #dddfe3 80%, #f5f6f6 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f6f6', endColorstr='#f5f6f6',GradientType=0 ); /* IE6-9 */[/CODE]
be sure to add it under the code in
[CODE lang="css" title="Code To Add Beneath" highlight="19"]#player
{
width:400px;
margin-left:300px;
padding:5px;
box-sizing:border-box;
-webkit-border-top-right-radius: 15px;
-moz-border-radius-topright: 15px;
border-top-right-radius: 15px;
-webkit-border-bottom-right-radius: 15px;
-moz-border-radius-bottomright: 15px;
border-bottom-right-radius: 15px;
-webkit-border-bottom-left-radius: 15px;
-moz-border-radius-bottomleft: 15px;
border-bottom-left-radius: 15px;
-webkit-border-top-left-radius: 15px;
-moz-border-radius-topleft: 15px;
border-top-left-radius: 15px;

}[/CODE]
 
I try to collect data from some other websites and make my own clip, but am facing css file. First of all i start with
<!-- (A) PLAY/PAUSE BUTTON -->
<button id="aPlay" disabled>Play</button>

<!-- (B) TRACK TIME -->
<span id="aNow"></span> / <span id="aTime"></span>

<!-- (C) SEEK BAR -->
<input id="aSeek" type="range" min="0" value="0" step="1" disabled/>

<!-- (D) VOLUME SLIDE -->
<input id="aVolume" type="range" min="0" max="1" value="1" step="0.1" disabled/>
You haven't said what problem you have, and I think it's better if you post this in a new thread. :)

Btw when posting code please put is in the code feature (the </> button).
1644164924959.png
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom