sldshr commited on
Commit
569ae2e
·
verified ·
1 Parent(s): c308318

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +60 -11
index.html CHANGED
@@ -390,6 +390,7 @@
390
  window.viewSaveTimeout = null;
391
  let blobUrls = [];
392
  let currentVideoPlayer = null;
 
393
 
394
  function generateSlug(title) {
395
  let slug = title.toLowerCase().trim();
@@ -908,10 +909,11 @@
908
 
909
  // ==================== КЛАСС КАСТОМНОГО ВИДЕОПЛЕЕРА ====================
910
  class CustomVideoPlayer {
911
- constructor(container, src, autoPlay = false) {
912
  this.container = container;
913
  this.src = src;
914
  this.autoPlay = autoPlay;
 
915
  this.video = null;
916
  this.progressBar = null;
917
  this.progressFilled = null;
@@ -930,12 +932,16 @@
930
  <div class="custom-video-player">
931
  <video src="${this.src}" preload="auto" playsinline tabindex="0"></video>
932
  <div class="video-controls">
933
- <button class="play-pause-btn" title="Play/Pause">▶</button>
 
 
934
  <div class="progress-container">
935
  <div class="progress-bar"></div>
936
  </div>
937
  <span class="time-display"><span class="time-current">0:00</span> / <span class="time-duration">0:00</span></span>
938
- <button class="mute-btn" title="Mute/Unmute">🔊</button>
 
 
939
  <input type="range" class="volume-slider" min="0" max="1" step="0.01" value="1">
940
  </div>
941
  </div>
@@ -950,6 +956,22 @@
950
  this.timeCurrent = this.container.querySelector('.time-current');
951
  this.timeDuration = this.container.querySelector('.time-duration');
952
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  // Обработчики для перетаскивания прогресса
954
  this.progressContainer.addEventListener('mousedown', (e) => this.startDrag(e));
955
  this.progressContainer.addEventListener('touchstart', (e) => this.startDrag(e), {passive: false});
@@ -969,10 +991,10 @@
969
  }
970
  });
971
  this.video.addEventListener('play', () => {
972
- this.playPauseBtn.textContent = '⏸';
973
  });
974
  this.video.addEventListener('pause', () => {
975
- this.playPauseBtn.textContent = '▶';
976
  });
977
  this.playPauseBtn.addEventListener('click', () => this.togglePlay());
978
  this.video.addEventListener('click', () => this.togglePlay());
@@ -986,10 +1008,24 @@
986
  // Клавиатурное управление
987
  this.video.addEventListener('keydown', (e) => this.handleKeydown(e));
988
 
989
- if (this.autoPlay) {
990
- this.video.autoplay = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
991
  }
992
- this.video.play().catch(e => console.log('Autoplay prevented'));
993
 
994
  currentVideoPlayer = this;
995
  }
@@ -1066,9 +1102,9 @@
1066
 
1067
  updateMuteIcon() {
1068
  if (this.video.muted || this.video.volume === 0) {
1069
- this.muteBtn.textContent = '🔇';
1070
  } else {
1071
- this.muteBtn.textContent = '🔊';
1072
  }
1073
  if (this.video.volume > 0 && !this.video.muted) {
1074
  this.volumeSlider.value = this.video.volume;
@@ -1084,8 +1120,18 @@
1084
  return `${mins}:${secs.toString().padStart(2, '0')}`;
1085
  }
1086
 
 
 
 
 
 
 
 
 
1087
  destroy() {
 
1088
  if (this.video) {
 
1089
  this.video.pause();
1090
  this.video.src = '';
1091
  this.video.load();
@@ -1123,7 +1169,10 @@
1123
  container.innerHTML = '';
1124
 
1125
  if (media.type === 'video') {
1126
- const player = new CustomVideoPlayer(container, media.url, true);
 
 
 
1127
  currentVideoPlayer = player;
1128
  } else {
1129
  const img = document.createElement('img');
 
390
  window.viewSaveTimeout = null;
391
  let blobUrls = [];
392
  let currentVideoPlayer = null;
393
+ let videoStates = {}; // Состояния плееров для восстановления
394
 
395
  function generateSlug(title) {
396
  let slug = title.toLowerCase().trim();
 
909
 
910
  // ==================== КЛАСС КАСТОМНОГО ВИДЕОПЛЕЕРА ====================
911
  class CustomVideoPlayer {
912
+ constructor(container, src, autoPlay = false, initialState = null) {
913
  this.container = container;
914
  this.src = src;
915
  this.autoPlay = autoPlay;
916
+ this.initialState = initialState;
917
  this.video = null;
918
  this.progressBar = null;
919
  this.progressFilled = null;
 
932
  <div class="custom-video-player">
933
  <video src="${this.src}" preload="auto" playsinline tabindex="0"></video>
934
  <div class="video-controls">
935
+ <button class="play-pause-btn" title="Play/Pause">
936
+ <svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
937
+ </button>
938
  <div class="progress-container">
939
  <div class="progress-bar"></div>
940
  </div>
941
  <span class="time-display"><span class="time-current">0:00</span> / <span class="time-duration">0:00</span></span>
942
+ <button class="mute-btn" title="Mute/Unmute">
943
+ <svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>
944
+ </button>
945
  <input type="range" class="volume-slider" min="0" max="1" step="0.01" value="1">
946
  </div>
947
  </div>
 
956
  this.timeCurrent = this.container.querySelector('.time-current');
957
  this.timeDuration = this.container.querySelector('.time-duration');
958
 
959
+ // Применение сохранённого состояния
960
+ if (this.initialState) {
961
+ if (this.initialState.currentTime) {
962
+ this.video.addEventListener('loadedmetadata', () => {
963
+ this.video.currentTime = this.initialState.currentTime;
964
+ });
965
+ }
966
+ if (this.initialState.volume !== undefined) {
967
+ this.video.volume = this.initialState.volume;
968
+ this.volumeSlider.value = this.initialState.volume;
969
+ }
970
+ if (this.initialState.paused !== undefined) {
971
+ this.video.paused = this.initialState.paused; // автоматически не применится, но установим позже
972
+ }
973
+ }
974
+
975
  // Обработчики для перетаскивания прогресса
976
  this.progressContainer.addEventListener('mousedown', (e) => this.startDrag(e));
977
  this.progressContainer.addEventListener('touchstart', (e) => this.startDrag(e), {passive: false});
 
991
  }
992
  });
993
  this.video.addEventListener('play', () => {
994
+ this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>';
995
  });
996
  this.video.addEventListener('pause', () => {
997
+ this.playPauseBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>';
998
  });
999
  this.playPauseBtn.addEventListener('click', () => this.togglePlay());
1000
  this.video.addEventListener('click', () => this.togglePlay());
 
1008
  // Клавиатурное управление
1009
  this.video.addEventListener('keydown', (e) => this.handleKeydown(e));
1010
 
1011
+ // Установка состояния паузы после загрузки метаданных
1012
+ if (this.initialState && this.initialState.paused !== undefined) {
1013
+ this.video.addEventListener('loadedmetadata', () => {
1014
+ if (this.initialState.paused) {
1015
+ this.video.pause();
1016
+ } else {
1017
+ this.video.play().catch(e => console.log('Autoplay prevented'));
1018
+ }
1019
+ });
1020
+ } else if (this.autoPlay) {
1021
+ this.video.play().catch(e => console.log('Autoplay prevented'));
1022
+ }
1023
+
1024
+ if (this.initialState && this.initialState.volume !== undefined) {
1025
+ this.video.volume = this.initialState.volume;
1026
+ this.volumeSlider.value = this.initialState.volume;
1027
+ this.updateMuteIcon();
1028
  }
 
1029
 
1030
  currentVideoPlayer = this;
1031
  }
 
1102
 
1103
  updateMuteIcon() {
1104
  if (this.video.muted || this.video.volume === 0) {
1105
+ this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>';
1106
  } else {
1107
+ this.muteBtn.innerHTML = '<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>';
1108
  }
1109
  if (this.video.volume > 0 && !this.video.muted) {
1110
  this.volumeSlider.value = this.video.volume;
 
1120
  return `${mins}:${secs.toString().padStart(2, '0')}`;
1121
  }
1122
 
1123
+ saveState() {
1124
+ return {
1125
+ currentTime: this.video.currentTime,
1126
+ volume: this.video.volume,
1127
+ paused: this.video.paused
1128
+ };
1129
+ }
1130
+
1131
  destroy() {
1132
+ // Сохраняем состояние перед уничтожением
1133
  if (this.video) {
1134
+ videoStates[this.container.dataset.stateKey] = this.saveState();
1135
  this.video.pause();
1136
  this.video.src = '';
1137
  this.video.load();
 
1169
  container.innerHTML = '';
1170
 
1171
  if (media.type === 'video') {
1172
+ const stateKey = `${slug}_${index}`;
1173
+ container.dataset.stateKey = stateKey;
1174
+ const savedState = videoStates[stateKey] || null;
1175
+ const player = new CustomVideoPlayer(container, media.url, true, savedState);
1176
  currentVideoPlayer = player;
1177
  } else {
1178
  const img = document.createElement('img');