soiz1 commited on
Commit
00b3624
·
1 Parent(s): 8b06cde

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +32 -13
index.html CHANGED
@@ -1129,27 +1129,46 @@ document.addEventListener('DOMContentLoaded', function() {
1129
  video.preservesPitch = true;
1130
  video.mozPreservesPitch = true; // Firefox用
1131
  video.webkitPreservesPitch = true; // 古いWebKit用
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1132
  document.addEventListener('visibilitychange', async () => {
1133
  if (document.hidden) {
1134
- // 他のタブに移動したとき → PiP起動
1135
- if (!document.pictureInPictureElement && !video.paused) {
 
1136
  try {
1137
- await video.requestPictureInPicture();
1138
- } catch (err) {
1139
- console.error('PiP開始失敗:', err);
1140
  }
1141
  }
 
1142
  } else {
1143
- // ページに戻ってきたとき → PiPを閉じる
1144
- if (document.pictureInPictureElement) {
1145
- try {
1146
- await document.exitPictureInPicture();
1147
- } catch (err) {
1148
- console.error('PiP終了失敗:', err);
1149
- }
1150
- }
1151
  }
1152
  });
 
 
 
1153
  const videoContainer = document.getElementById('video-container');
1154
  const playPauseBtn = document.getElementById('play-pause-btn');
1155
  const timeDisplay = document.getElementById('time-display');
 
1129
  video.preservesPitch = true;
1130
  video.mozPreservesPitch = true; // Firefox用
1131
  video.webkitPreservesPitch = true; // 古いWebKit用
1132
+ async function enterPiP() {
1133
+ if (!document.pictureInPictureElement && !video.paused) {
1134
+ try {
1135
+ await video.requestPictureInPicture();
1136
+ } catch (err) {
1137
+ console.warn('PiP開始失敗:', err);
1138
+ }
1139
+ }
1140
+ }
1141
+
1142
+ async function exitPiP() {
1143
+ if (document.pictureInPictureElement) {
1144
+ try {
1145
+ await document.exitPictureInPicture();
1146
+ } catch (err) {
1147
+ console.warn('PiP終了失敗:', err);
1148
+ }
1149
+ }
1150
+ }
1151
+
1152
  document.addEventListener('visibilitychange', async () => {
1153
  if (document.hidden) {
1154
+ // 他タブに移動 → PiP表示
1155
+ // 動画が停止していれば再生再開
1156
+ if (video.paused) {
1157
  try {
1158
+ await video.play();
1159
+ } catch (e) {
1160
+ console.warn('再生エラー:', e);
1161
  }
1162
  }
1163
+ enterPiP();
1164
  } else {
1165
+ // タブに戻ったとき → PiP終了
1166
+ exitPiP();
 
 
 
 
 
 
1167
  }
1168
  });
1169
+
1170
+ // 動画終了時に自動的にPiPを閉じる(次回再開のため)
1171
+ video.addEventListener('ended', exitPiP);
1172
  const videoContainer = document.getElementById('video-container');
1173
  const playPauseBtn = document.getElementById('play-pause-btn');
1174
  const timeDisplay = document.getElementById('time-display');