Wednesday, 29 October 2014

Create Audio Palyer in jquery,html5 and css3- part2

Step 5 – Controls Buttons

Now we will style the player controls (play/pause, mute/unmute). To do it we will start by giving some general styles to the buttons and then we’ll set a fixed width and height. We will position the “pause/play” buttons and“mute/unmute” buttons in the same position and they will toggle on click event.
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
.mejs-controls .mejs-button button {
    cursorpointer;
    displayblock;
    positionabsolute;
    text-indent-9999px;
}
 
.mejs-controls .mejs-play button,
.mejs-controls .mejs-pause button {
    width21px;
    height21px;
    top35px;
    left135px;
    backgroundtransparent url(../img/play-pause.png) 0 0;
}
 
.mejs-controls .mejs-pause button { background-position:0 -21px; }
 
.mejs-controls .mejs-mute button,
.mejs-controls .mejs-unmute button {
    width14px;
    height12px;
    top70px;
    left140px;
    backgroundtransparent url(../img/mute-unmute.png) 0 0;
}
 
.mejs-controls .mejs-unmute button { background-position0 -12px; }

Step 6 – Volume Slider

To style the volume slider we’ll position it, then we will give a 200px width and 8px height. We also need to set a background color, some shadows and rounded corners.
.mejs-controls div.mejs-horizontal-volume-slider {
    positionabsolute;
    top71px;
    left165px;
    cursorpointer;
}
 
.mejs-controls .mejs-horizontal-volume-slider 
.mejs-horizontal-volume-total {
    width200px;
    height8px;
    background#212227;
 
    -webkit-box-shadow: inset 0px 1px 0px rgba(0,0,0, .3),
 0px 1px 0px rgba(255,255,255, .25);
    -moz-box-shadow: inset 0px 1px 0px rgba(0,0,0, .3), 
0px 1px 0px rgba(255,255,255, .25);
    box-shadow: inset 0px 1px 0px rgba(0,0,0, .3), 
0px 1px 0px rgba(255,255,255, .25);
 
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
}
Then we need to style the “current volume”, to do it we’ll add a custom image background, rounded corners, etc.
.mejs-controls .mejs-horizontal-volume-slider 
.mejs-horizontal-volume-current {
    positionabsolute;
    width0;
    height6px;
    top1px;
    left1px;
    backgroundurl(../img/volume-bar.png) repeat-x;
 
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
}

Step 7 – Progress Bar

The progress bar styles are almost basics. We will give the same width as the player container (400px) and position it to the bottom. We will also make the left and right corner rounded. Then we will set some background colors for each time state (total, loaded and current). As you may notice we need to set the width to 0 for the loaded and current time and as the song plays or is loaded the width will increase.
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
.mejs-controls div.mejs-time-rail { width400px; }
 
.mejs-controls .mejs-time-rail span {
    positionabsolute;
    displayblock;
    width400px;
    height5px;
    left0;
    bottom0;
    cursorpointer;
 
    -webkit-border-radius: 0px 0px 2px 2px;
    -moz-border-radius: 0px 0px 2px 2px;
    border-radius: 0px 0px 2px 2px;
}
 
.mejs-controls .mejs-time-rail .mejs-time-total { background#999999; }
 
.mejs-controls .mejs-time-rail .mejs-time-loaded {
    width0;
    background#cccccc;
}
 
.mejs-controls .mejs-time-rail .mejs-time-current {
    width0;
    background#64b44c;
}

Step 8 – Progres & Volume Handle

Now we will add a handle to the progress bar and volume slider. Basically we will only add a background image, set the width / height and position it.
1
2
3
4
5
6
7
8
9
10
11
.mejs-controls .mejs-time-rail .mejs-time-handle,
.mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-handle {
    positionabsolute;
    displayblock;
    width12px;
    height14px;
    top-4px;
    backgroundurl(../img/handle.png) no-repeat;
}
 
.mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-handle { top-2px; }

Step 9 – Time Tooltip

To finish the audio player we will add a time tooltip that will appear when we hover over the progress bar. The styles are almost the same as in the other steps, we will position it, add a fixed width/height values and a background image. We will also add some typography styles.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.mejs-controls .mejs-time-rail .mejs-time-float {
    positionabsolute;
    displaynone;
    width33px;
    height23px;
    top-26px;
    margin-left-17px;
    backgroundurl(../img/time-box.png);
}
 
.mejs-controls .mejs-time-rail .mejs-time-float-current {
    width33px;
    displayblock;
    left0;
    top4px;
 
    font-familyHelveticaArialsans-serif;
    font-size10px;
    font-weightbold;
    color#666666;
    text-aligncenter;
}

Conclusion

We’ve successfully coded this Audio Player.


No comments:

Post a Comment