Fazbeeer commited on
Commit
0d114fb
·
verified ·
1 Parent(s): ffdd543

Embed muted autoplay + provide a unmute button

Browse files

Use something like:

<iframe id="bg-music"
width="0" height="0"
src="https://www.youtube.com/embed/kSlPMMxZfys?autoplay=1&mute=1&enablejsapi=1"
allow="autoplay; encrypted-media"
frameborder="0"
></iframe>

Files changed (3) hide show
  1. index.html +3 -4
  2. script.js +44 -1
  3. style.css +7 -0
index.html CHANGED
@@ -49,7 +49,7 @@
49
  <!-- YouTube Background Music -->
50
  <iframe id="bg-music"
51
  width="0" height="0"
52
- src="https://www.youtube.com/embed/kSlPMMxZfys?enablejsapi=1&autoplay=1&mute=1"
53
  frameborder="0"
54
  allow="autoplay; encrypted-media"
55
  allowfullscreen>
@@ -58,10 +58,9 @@
58
  <!-- Mute/unmute button -->
59
  <button id="mute-btn"
60
  style="position: fixed; bottom: 20px; right: 20px; padding: 10px 20px; background: rgba(0,0,0,0.7); color: white; border: 1px solid #e3b341; border-radius: 50%; width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; z-index: 1000; cursor: pointer;">
61
- 🔇
62
  </button>
63
-
64
- <!-- Enhanced Vanta.js Background -->
65
  <div id="vanta-bg" class="fixed top-0 left-0 w-full h-full z-0 opacity-90"></div>
66
  <div class="fixed top-0 left-0 w-full h-full z-0 bg-gradient-to-b from-black via-transparent to-black opacity-30"></div>
67
  <!-- Google Translate -->
 
49
  <!-- YouTube Background Music -->
50
  <iframe id="bg-music"
51
  width="0" height="0"
52
+ src="https://www.youtube.com/embed/kSlPMMxZfys?enablejsapi=1&autoplay=1&mute=1&loop=1&playlist=kSlPMMxZfys"
53
  frameborder="0"
54
  allow="autoplay; encrypted-media"
55
  allowfullscreen>
 
58
  <!-- Mute/unmute button -->
59
  <button id="mute-btn"
60
  style="position: fixed; bottom: 20px; right: 20px; padding: 10px 20px; background: rgba(0,0,0,0.7); color: white; border: 1px solid #e3b341; border-radius: 50%; width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; z-index: 1000; cursor: pointer;">
61
+ <i data-feather="volume-x"></i>
62
  </button>
63
+ <!-- Enhanced Vanta.js Background -->
 
64
  <div id="vanta-bg" class="fixed top-0 left-0 w-full h-full z-0 opacity-90"></div>
65
  <div class="fixed top-0 left-0 w-full h-full z-0 bg-gradient-to-b from-black via-transparent to-black opacity-30"></div>
66
  <!-- Google Translate -->
script.js CHANGED
@@ -1,7 +1,50 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  // Shared JavaScript across all pages
3
  document.addEventListener('DOMContentLoaded', () => {
4
- // Handle support form submission
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  const supportForm = document.getElementById('supportForm');
6
  if (supportForm) {
7
  supportForm.addEventListener('submit', function(e) {
 
1
 
2
+ // YouTube API setup
3
+ let player;
4
+ function onYouTubeIframeAPIReady() {
5
+ player = new YT.Player('bg-music', {
6
+ events: {
7
+ 'onReady': onPlayerReady
8
+ }
9
+ });
10
+ }
11
+
12
+ function onPlayerReady(event) {
13
+ // Player is ready
14
+ updateMuteButton();
15
+ }
16
+
17
+ function updateMuteButton() {
18
+ const muteBtn = document.getElementById('mute-btn');
19
+ if (player.isMuted()) {
20
+ muteBtn.innerHTML = '<i data-feather="volume-x"></i>';
21
+ } else {
22
+ muteBtn.innerHTML = '<i data-feather="volume-2"></i>';
23
+ }
24
+ feather.replace();
25
+ }
26
+
27
  // Shared JavaScript across all pages
28
  document.addEventListener('DOMContentLoaded', () => {
29
+ // Load YouTube API script
30
+ const tag = document.createElement('script');
31
+ tag.src = "https://www.youtube.com/iframe_api";
32
+ const firstScriptTag = document.getElementsByTagName('script')[0];
33
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
34
+
35
+ // Mute/unmute button functionality
36
+ const muteBtn = document.getElementById('mute-btn');
37
+ muteBtn.addEventListener('click', () => {
38
+ if (player) {
39
+ if (player.isMuted()) {
40
+ player.unMute();
41
+ } else {
42
+ player.mute();
43
+ }
44
+ updateMuteButton();
45
+ }
46
+ });
47
+ // Handle support form submission
48
  const supportForm = document.getElementById('supportForm');
49
  if (supportForm) {
50
  supportForm.addEventListener('submit', function(e) {
style.css CHANGED
@@ -193,6 +193,13 @@ body::after {
193
  .goog-te-menu2-item-selected {
194
  background-color: rgba(227, 179, 65, 0.2) !important;
195
  }
 
 
 
 
 
 
 
196
  .feature-icon {
197
  width: 60px;
198
  height: 60px;
 
193
  .goog-te-menu2-item-selected {
194
  background-color: rgba(227, 179, 65, 0.2) !important;
195
  }
196
+ /* YouTube player controls */
197
+ #mute-btn i {
198
+ width: 24px;
199
+ height: 24px;
200
+ stroke-width: 2;
201
+ }
202
+
203
  .feature-icon {
204
  width: 60px;
205
  height: 60px;