File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2+ const audio = document . getElementById ( "audio" ) ;
3+ const playPauseButton = document . getElementById ( "playPause" ) ;
4+ const stopButton = document . getElementById ( "stop" ) ;
5+ const volumeUpButton = document . getElementById ( "volumeUp" ) ;
6+ const volumeDownButton = document . getElementById ( "volumeDown" ) ;
7+
8+ playPauseButton . addEventListener ( "click" , function ( ) {
9+ if ( audio . paused ) {
10+ audio . play ( ) ;
11+ playPauseButton . innerHTML = "Pause" ;
12+ } else {
13+ audio . pause ( ) ;
14+ playPauseButton . innerHTML = "Play" ;
15+ }
16+ } ) ;
17+
18+ stopButton . addEventListener ( "click" , function ( ) {
19+ audio . pause ( ) ;
20+ audio . currentTime = 0 ;
21+ playPauseButton . innerHTML = "Play" ;
22+ } ) ;
23+
24+ volumeUpButton . addEventListener ( "click" , function ( ) {
25+ if ( audio . volume < 1.0 ) {
26+ audio . volume += 0.1 ;
27+ }
28+ } ) ;
29+
30+ volumeDownButton . addEventListener ( "click" , function ( ) {
31+ if ( audio . volume > 0.0 ) {
32+ audio . volume -= 0.1 ;
33+ }
34+ } ) ;
35+ } ) ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+
4+ < head >
5+ < title > Simple Audio Player</ title >
6+ </ head >
7+
8+ < body >
9+ < h1 > Simple Audio Player</ h1 >
10+ < audio id ="audio " controls >
11+ < source src ="audio-file.mp3 " type ="audio/mpeg ">
12+ Your browser does not support the audio element.
13+ </ audio >
14+ < button id ="playPause "> Play/Pause</ button >
15+ < button id ="stop "> Stop</ button >
16+ < button id ="volumeUp "> Volume Up</ button >
17+ < button id ="volumeDown "> Volume Down</ button >
18+
19+ < script src ="audioPlayer.js "> </ script >
20+ </ body >
21+
22+ </ html >
You can’t perform that action at this time.
0 commit comments