Skip to content

Commit a514f29

Browse files
authored
Merge pull request #57 from DiptanshuG/main
feat: Add a simple audio player using HTML and JavaScript
2 parents 247f7ae + 5c1ba84 commit a514f29

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

AudioPlayer/audio-file.mp3

716 KB
Binary file not shown.

AudioPlayer/audioPlayer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
});

AudioPlayer/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>

0 commit comments

Comments
 (0)