-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from DiptanshuG/main
feat: Add a simple audio player using HTML and JavaScript
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
const audio = document.getElementById("audio"); | ||
const playPauseButton = document.getElementById("playPause"); | ||
const stopButton = document.getElementById("stop"); | ||
const volumeUpButton = document.getElementById("volumeUp"); | ||
const volumeDownButton = document.getElementById("volumeDown"); | ||
|
||
playPauseButton.addEventListener("click", function () { | ||
if (audio.paused) { | ||
audio.play(); | ||
playPauseButton.innerHTML = "Pause"; | ||
} else { | ||
audio.pause(); | ||
playPauseButton.innerHTML = "Play"; | ||
} | ||
}); | ||
|
||
stopButton.addEventListener("click", function () { | ||
audio.pause(); | ||
audio.currentTime = 0; | ||
playPauseButton.innerHTML = "Play"; | ||
}); | ||
|
||
volumeUpButton.addEventListener("click", function () { | ||
if (audio.volume < 1.0) { | ||
audio.volume += 0.1; | ||
} | ||
}); | ||
|
||
volumeDownButton.addEventListener("click", function () { | ||
if (audio.volume > 0.0) { | ||
audio.volume -= 0.1; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Simple Audio Player</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Simple Audio Player</h1> | ||
<audio id="audio" controls> | ||
<source src="audio-file.mp3" type="audio/mpeg"> | ||
Your browser does not support the audio element. | ||
</audio> | ||
<button id="playPause">Play/Pause</button> | ||
<button id="stop">Stop</button> | ||
<button id="volumeUp">Volume Up</button> | ||
<button id="volumeDown">Volume Down</button> | ||
|
||
<script src="audioPlayer.js"></script> | ||
</body> | ||
|
||
</html> |