1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
| <div class="bilibili-player-container"> <div class="input-section"> <label for="bvid-input">输入B站视频BV号:</label> <div class="input-group"> <input type="text" id="bvid-input" placeholder="例如:BV1om4y1Y771" value="BV1om4y1Y771"> <button onclick="loadBilibiliVideo()">🎬 播放视频</button> <button onclick="clearVideo()">🗑️ 清空</button> </div> <div class="preset-videos"> <span>快速选择:</span> <button onclick="loadPresetVideo('BV1om4y1Y771')">示例视频1</button> <button onclick="loadPresetVideo('BV1xx411c7mD')">示例视频2</button> <button onclick="loadPresetVideo('BV1uv411q7Mv')">示例视频3</button> </div> </div> <div class="video-player"> <iframe id="bilibili-iframe" src="//player.bilibili.com/player.html?bvid=BV1om4y1Y771&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" width="100%" height="400"> </iframe> </div> <div class="video-info" id="video-info"> <p>当前播放:BV1om4y1Y771</p> </div> </div>
<script> function loadBilibiliVideo() { const bvidInput = document.getElementById('bvid-input'); const iframe = document.getElementById('bilibili-iframe'); const videoInfo = document.getElementById('video-info'); let bvid = bvidInput.value.trim(); if (!bvid) { alert('请输入BV号!'); return; } if (!bvid.startsWith('BV')) { bvid = 'BV' + bvid; } const bvidPattern = /^BV[a-zA-Z0-9]{10}$/; if (!bvidPattern.test(bvid)) { alert('BV号格式不正确!请检查输入(例如:BV1om4y1Y771)'); return; } const newSrc = `//player.bilibili.com/player.html?bvid=${bvid}&page=1`; iframe.src = newSrc; videoInfo.innerHTML = `<p>当前播放:${bvid} <span class="loading">加载中...</span></p>`; setTimeout(() => { videoInfo.innerHTML = `<p>当前播放:${bvid} <span class="success">✅ 加载完成</span></p>`; }, 3000); }
function loadPresetVideo(bvid) { const bvidInput = document.getElementById('bvid-input'); bvidInput.value = bvid; loadBilibiliVideo(); }
function clearVideo() { const bvidInput = document.getElementById('bvid-input'); const iframe = document.getElementById('bilibili-iframe'); const videoInfo = document.getElementById('video-info'); bvidInput.value = ''; iframe.src = 'about:blank'; videoInfo.innerHTML = '<p>请输入BV号来播放视频</p>'; }
document.getElementById('bvid-input').addEventListener('keypress', function(e) { if (e.key === 'Enter') { loadBilibiliVideo(); } }); </script>
<style> .bilibili-player-container { max-width: 800px; margin: 20px auto; padding: 20px; border: 2px solid #00A1D6; border-radius: 12px; background: linear-gradient(135deg, #f8f9ff 0%, #e8f4ff 100%); box-shadow: 0 4px 12px rgba(0, 161, 214, 0.1); }
.input-section { margin-bottom: 20px; }
.input-section label { display: block; margin-bottom: 8px; font-weight: bold; color: #333; }
.input-group { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }
.input-group input { flex: 1; min-width: 200px; padding: 10px 15px; border: 2px solid #ddd; border-radius: 6px; font-size: 14px; transition: border-color 0.3s; }
.input-group input:focus { outline: none; border-color: #00A1D6; box-shadow: 0 0 0 3px rgba(0, 161, 214, 0.1); }
.input-group button { padding: 10px 20px; background: #00A1D6; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: bold; transition: all 0.3s; white-space: nowrap; }
.input-group button:hover { background: #0088BB; transform: translateY(-1px); }
.input-group button:last-child { background: #FF6B6B; }
.input-group button:last-child:hover { background: #FF5252; }
.preset-videos { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.preset-videos span { color: #666; font-size: 14px; }
.preset-videos button { padding: 6px 12px; background: #f0f0f0; color: #333; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; font-size: 12px; transition: all 0.3s; }
.preset-videos button:hover { background: #00A1D6; color: white; border-color: #00A1D6; }
.video-player { margin-bottom: 15px; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); }
.video-info { text-align: center; padding: 10px; background: rgba(255, 255, 255, 0.8); border-radius: 6px; }
.video-info p { margin: 0; color: #333; }
.loading { color: #FF9800; animation: pulse 1.5s infinite; }
.success { color: #4CAF50; }
@keyframes pulse { 0%, 50%, 100% { opacity: 1; } 25%, 75% { opacity: 0.5; } }
@media (max-width: 600px) { .input-group { flex-direction: column; } .input-group input { min-width: auto; } .preset-videos { flex-direction: column; align-items: flex-start; } } </style>
|