akhaliq HF Staff commited on
Commit
7492b32
·
verified ·
1 Parent(s): e2cdc43

audio in video not playing in some devices - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +35 -13
index.html CHANGED
@@ -65,7 +65,7 @@
65
  <p class="text-white/70 text-xl">Loading Nexus Robotics Experience</p>
66
  </div>
67
  </div>
68
- <video id="bgVideo" autoplay loop playsinline muted class="w-full h-full object-cover">
69
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.mp4" type="video/mp4">
70
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.webm" type="video/webm">
71
  </video>
@@ -145,19 +145,31 @@
145
  return;
146
  }
147
 
148
- // Try to play video
149
- const playPromise = video.play();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
- if (playPromise !== undefined) {
152
- playPromise.then(() => {
153
- // Video playing successfully
154
- fallback.classList.add('hidden');
155
- }).catch(error => {
156
- // Video failed to play
157
- video.style.display = 'none';
158
- fallback.classList.remove('hidden');
159
- });
160
- }
161
 
162
  // Fallback if video doesn't load within 5 seconds
163
  setTimeout(() => {
@@ -177,6 +189,16 @@
177
  soundToggle.innerHTML = video.muted
178
  ? '<i class="fas fa-volume-mute text-white text-xl"></i>'
179
  : '<i class="fas fa-volume-up text-white text-xl"></i>';
 
 
 
 
 
 
 
 
 
 
180
  });
181
 
182
  // Simple animation for the join button
 
65
  <p class="text-white/70 text-xl">Loading Nexus Robotics Experience</p>
66
  </div>
67
  </div>
68
+ <video id="bgVideo" autoplay loop playsinline muted class="w-full h-full object-cover" preload="auto" poster="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">
69
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.mp4" type="video/mp4">
70
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.webm" type="video/webm">
71
  </video>
 
145
  return;
146
  }
147
 
148
+ // Try to play video with audio handling
149
+ const tryPlay = () => {
150
+ const playPromise = video.play();
151
+
152
+ if (playPromise !== undefined) {
153
+ playPromise.then(() => {
154
+ // Video playing successfully
155
+ fallback.classList.add('hidden');
156
+ }).catch(error => {
157
+ // Try again without mute if muted
158
+ if (video.muted) {
159
+ video.muted = false;
160
+ tryPlay();
161
+ } else {
162
+ // Final fallback
163
+ video.style.display = 'none';
164
+ fallback.classList.remove('hidden');
165
+ }
166
+ });
167
+ }
168
+ };
169
 
170
+ // Start with muted video for autoplay compliance
171
+ video.muted = true;
172
+ tryPlay();
 
 
 
 
 
 
 
173
 
174
  // Fallback if video doesn't load within 5 seconds
175
  setTimeout(() => {
 
189
  soundToggle.innerHTML = video.muted
190
  ? '<i class="fas fa-volume-mute text-white text-xl"></i>'
191
  : '<i class="fas fa-volume-up text-white text-xl"></i>';
192
+
193
+ // Try to unmute if user clicked to enable sound
194
+ if (!video.muted) {
195
+ video.play().catch(e => {
196
+ // If unmute fails, show message
197
+ alert('Audio playback requires user interaction. Please tap/click anywhere else on the page first.');
198
+ video.muted = true;
199
+ soundToggle.innerHTML = '<i class="fas fa-volume-mute text-white text-xl"></i>';
200
+ });
201
+ }
202
  });
203
 
204
  // Simple animation for the join button