Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio fixed #744

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
<body>
<script src="/js/global.js"></script>

<audio id="background-music" autoplay loop>
<source src="./assets/sounds/bgMusic.mp3" type="audio/mpeg" />
</audio>
<div id="permission">
<div>πŸ”’ This website is requesting access to autoplay music</div>
<button class="req1">Cancel</button>
<button class="req2" style="background-color: rgb(0, 200, 255);">Allow</button>
</div>
<div class="settings">
<video autoplay muted class="video" loop id="myVideo">
<source src="/assets/videos/1.mp4" type="video/mp4" />
Expand Down Expand Up @@ -176,9 +178,8 @@ <h3 class="instructions-heading" style="text-decoration: underline">
START
</a>
<button class="reset-btn button1" id="reset-btn">RESET</button>
<button id="music-toggle" onclick="toggleMusic()">
Music Off
</button>
<button id="music-toggle" style="font-size: 1.25rem;"><i
class="fas fa-volume-xmark"></i></button>
</div>
</div>
</div>
Expand Down
39 changes: 25 additions & 14 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,37 @@ function closeThankYouPopup() {
}

// Music toggle
var isPlaying = true;
function toggleMusic() {
var audio = document.getElementById("background-music");
var button = document.getElementById("music-toggle");
let isPlaying = true;
const access = document.getElementById("permission");
const button = document.getElementById("music-toggle").children[0];
const audio = new Audio("/assets/sounds/bgMusic.mp3");

document.querySelector(".req1").addEventListener("click", () => {
access.style.display = "none";
isPlaying = false;
button.classList.remove("fa-volume-high");
button.classList.add("fa-volume-xmark");
});

document.querySelector(".req2").addEventListener("click", () => {
access.style.display = "none";
audio.play();
button.classList.remove("fa-volume-xmark");
button.classList.add("fa-volume-high");
});

document.getElementById("music-toggle").addEventListener("click", () => {
if (isPlaying) {
audio.pause();
button.textContent = "Music On";
button.classList.add("fa-volume-xmark");
button.classList.remove("fa-volume-high");
} else {
audio.play();
button.textContent = "Music Off";
button.classList.add("fa-volume-high");
button.classList.remove("fa-volume-xmark");
}
isPlaying = !isPlaying;
}

window.onload = function () {
var audio = document.getElementById("background-music");
audio.play();
var button = document.getElementById("music-toggle");
button.textContent = "Music Off";
};
});

// Cursor -->
document.addEventListener("DOMContentLoaded", function () {
Expand Down
44 changes: 44 additions & 0 deletions styles/index.style.css
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,50 @@ input[type="email"]:focus {
color: white;
}

/* Permission box */

#permission {
position: absolute;
bottom: 0;
left: 0;
top: 0;
right: 0;
margin: auto;
background: #fff;
padding: 2rem;
border-radius: 25px;
text-align: center;
z-index: 10000;
width: fit-content;
height: fit-content;
}

#permission::before {
content: "";
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
z-index: -1;

}

#permission div {
font-size: 1.25rem;
}

.req1,
.req2 {
font-size: 1rem;
margin: 2rem 1rem 0 1rem;
padding: 0.75rem 1.25rem;
border-radius: 10px;
border: none;
background: silver;
}

.disabled {
opacity: 0.75;
}