akhaliq HF Staff commited on
Commit
658235d
·
verified ·
1 Parent(s): 9392d90

on mobile the video does not load in chrome or safari - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +41 -4
index.html CHANGED
@@ -65,6 +65,11 @@
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">
@@ -125,10 +130,12 @@
125
  </section>
126
 
127
  <script>
128
- // Enhanced video handling
129
  document.addEventListener('DOMContentLoaded', function() {
130
  const video = document.getElementById('bgVideo');
131
  const fallback = document.getElementById('videoFallback');
 
 
132
 
133
  // Show loading state initially
134
  fallback.classList.remove('hidden');
@@ -136,40 +143,70 @@
136
  // Check if video can play
137
  const canPlay = video.canPlayType('video/mp4') || video.canPlayType('video/webm');
138
 
 
 
 
 
 
 
 
139
  if (!canPlay) {
140
  // No video support at all
141
  video.style.display = 'none';
 
142
  return;
143
  }
144
 
145
  // Try to play video with audio handling
146
  const tryPlay = () => {
 
 
147
  const playPromise = video.play();
148
 
149
  if (playPromise !== undefined) {
150
  playPromise.then(() => {
151
  // Video playing successfully
152
  fallback.classList.add('hidden');
 
153
  }).catch(error => {
154
  // Final fallback if video can't play
155
  video.style.display = 'none';
156
  fallback.classList.remove('hidden');
 
157
  });
158
  }
159
  };
160
 
161
  // Start with muted video for autoplay compliance but unmute immediately
162
- video.muted = true;
163
- tryPlay();
164
- video.muted = false;
 
 
165
 
166
  // Fallback if video doesn't load within 5 seconds
167
  setTimeout(() => {
168
  if (video.readyState < 3) { // 3 = HAVE_FUTURE_DATA
169
  video.style.display = 'none';
170
  fallback.classList.remove('hidden');
 
171
  }
172
  }, 5000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  });
174
 
175
  // Simple animation for the join button
 
65
  <p class="text-white/70 text-xl">Loading Nexus Robotics Experience</p>
66
  </div>
67
  </div>
68
+ <div id="mobilePlayOverlay" class="md:hidden absolute inset-0 flex items-center justify-center z-20 bg-black/30">
69
+ <button class="bg-white/20 backdrop-blur-sm rounded-full p-4 border-2 border-white/30">
70
+ <i class="fas fa-play text-white text-4xl"></i>
71
+ </button>
72
+ </div>
73
  <video id="bgVideo" autoplay loop playsinline muted class="w-full h-full object-cover" preload="auto" poster="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">
74
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.mp4" type="video/mp4">
75
  <source src="https://huggingface.co/spaces/akhaliq/nexusrobotics/resolve/main/Video_of_Robot_Washing_Dishes.webm" type="video/webm">
 
130
  </section>
131
 
132
  <script>
133
+ // Enhanced video handling with mobile support
134
  document.addEventListener('DOMContentLoaded', function() {
135
  const video = document.getElementById('bgVideo');
136
  const fallback = document.getElementById('videoFallback');
137
+ const mobileOverlay = document.getElementById('mobilePlayOverlay');
138
+ const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
139
 
140
  // Show loading state initially
141
  fallback.classList.remove('hidden');
 
143
  // Check if video can play
144
  const canPlay = video.canPlayType('video/mp4') || video.canPlayType('video/webm');
145
 
146
+ // Handle mobile devices differently
147
+ if (isMobile) {
148
+ mobileOverlay.classList.remove('hidden');
149
+ video.muted = true;
150
+ video.autoplay = false;
151
+ video.removeAttribute('playsinline');
152
+
153
  if (!canPlay) {
154
  // No video support at all
155
  video.style.display = 'none';
156
+ if (isMobile) mobileOverlay.style.display = 'none';
157
  return;
158
  }
159
 
160
  // Try to play video with audio handling
161
  const tryPlay = () => {
162
+ if (isMobile) return;
163
+
164
  const playPromise = video.play();
165
 
166
  if (playPromise !== undefined) {
167
  playPromise.then(() => {
168
  // Video playing successfully
169
  fallback.classList.add('hidden');
170
+ if (isMobile) mobileOverlay.classList.add('hidden');
171
  }).catch(error => {
172
  // Final fallback if video can't play
173
  video.style.display = 'none';
174
  fallback.classList.remove('hidden');
175
+ if (isMobile) mobileOverlay.classList.add('hidden');
176
  });
177
  }
178
  };
179
 
180
  // Start with muted video for autoplay compliance but unmute immediately
181
+ if (!isMobile) {
182
+ video.muted = true;
183
+ tryPlay();
184
+ video.muted = false;
185
+ }
186
 
187
  // Fallback if video doesn't load within 5 seconds
188
  setTimeout(() => {
189
  if (video.readyState < 3) { // 3 = HAVE_FUTURE_DATA
190
  video.style.display = 'none';
191
  fallback.classList.remove('hidden');
192
+ if (isMobile) mobileOverlay.classList.add('hidden');
193
  }
194
  }, 5000);
195
+
196
+ // Mobile play button handler
197
+ if (isMobile) {
198
+ mobileOverlay.querySelector('button').addEventListener('click', () => {
199
+ video.play()
200
+ .then(() => {
201
+ mobileOverlay.classList.add('hidden');
202
+ fallback.classList.add('hidden');
203
+ })
204
+ .catch(e => {
205
+ mobileOverlay.querySelector('i').className = 'fas fa-exclamation-triangle text-red-500 text-4xl';
206
+ mobileOverlay.querySelector('button').classList.add('bg-red-500/20', 'border-red-500/30');
207
+ });
208
+ });
209
+ }
210
  });
211
 
212
  // Simple animation for the join button