soiz1 commited on
Commit
d7e11fc
·
verified ·
1 Parent(s): 5c90552

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +20 -10
index.html CHANGED
@@ -845,8 +845,8 @@ function setupFramePreview() {
845
  frameTime.textContent = `${previewMinutes}:${previewSeconds}`;
846
 
847
  // プレビュー位置を更新(プログレスバーの上に表示)
848
- framePreview.style.left = `${e.clientX}px`;
849
- framePreview.style.bottom = `${progressContainer.offsetHeight + 10}px`; // プログレスバーの上
850
  framePreview.style.display = 'block';
851
 
852
  // キャッシュがあればそれを使う
@@ -859,14 +859,24 @@ function setupFramePreview() {
859
  // フレームを取得
860
  VideoForThumbnail.currentTime = previewTime;
861
 
862
- VideoForThumbnail.addEventListener('seeked', function() {
863
- canvas.width = VideoForThumbnail.videoWidth;
864
- canvas.height = VideoForThumbnail.videoHeight;
865
- ctx.drawImage(VideoForThumbnail, 0, 0, canvas.width, canvas.height);
866
- const imageData = canvas.toDataURL('image/jpeg');
867
- previewImage.src = imageData;
868
- frameCache[cacheKey] = imageData; // キャッシュに保存
869
- }, { once: true });
 
 
 
 
 
 
 
 
 
 
870
  });
871
 
872
  progressContainer.addEventListener('mouseleave', () => {
 
845
  frameTime.textContent = `${previewMinutes}:${previewSeconds}`;
846
 
847
  // プレビュー位置を更新(プログレスバーの上に表示)
848
+ framePreview.style.left = `${e.clientX - 80}px`; // 中央寄せ
849
+ framePreview.style.bottom = `${progressContainer.offsetHeight + 10}px`;
850
  framePreview.style.display = 'block';
851
 
852
  // キャッシュがあればそれを使う
 
859
  // フレームを取得
860
  VideoForThumbnail.currentTime = previewTime;
861
 
862
+ const onSeeked = () => {
863
+ if (VideoForThumbnail.readyState >= 2) { // HAVE_CURRENT_DATA 以上か確認
864
+ canvas.width = VideoForThumbnail.videoWidth || 160;
865
+ canvas.height = VideoForThumbnail.videoHeight || 90;
866
+ ctx.drawImage(VideoForThumbnail, 0, 0, canvas.width, canvas.height);
867
+
868
+ try {
869
+ const imageData = canvas.toDataURL('image/jpeg');
870
+ previewImage.src = imageData;
871
+ frameCache[cacheKey] = imageData;
872
+ } catch (e) {
873
+ console.error("Failed to generate preview image:", e);
874
+ }
875
+ }
876
+ VideoForThumbnail.removeEventListener('seeked', onSeeked);
877
+ };
878
+
879
+ VideoForThumbnail.addEventListener('seeked', onSeeked);
880
  });
881
 
882
  progressContainer.addEventListener('mouseleave', () => {