2025-10-06 15:06:48 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
<html lang="zh-CN">
|
|
|
|
|
|
<head>
|
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
|
|
|
<title>萤石云播放器</title>
|
|
|
|
|
|
<style>
|
|
|
|
|
|
* {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
html, body {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
/* background: #1a1a1a; */
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#player-iframe {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 50%;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
object-fit: contain; /* 保持视频比例,不变形 */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
/* 简化的控制按钮样式 */
|
|
|
|
|
|
.control-buttons {
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
bottom: 30px;
|
|
|
|
|
|
left: 50%;
|
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
z-index: 999;
|
|
|
|
|
|
pointer-events: auto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.control-btn {
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.7);
|
|
|
|
|
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
|
|
|
|
border-radius: 25px;
|
|
|
|
|
|
padding: 12px 20px;
|
|
|
|
|
|
min-width: 100px;
|
|
|
|
|
|
min-height: 44px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
user-select: none;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.control-btn:active {
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.8);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.play-btn {
|
|
|
|
|
|
background: rgba(76, 175, 80, 0.8);
|
|
|
|
|
|
border-color: rgba(76, 175, 80, 0.9);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.play-btn:active {
|
|
|
|
|
|
background: rgba(76, 175, 80, 0.9);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.refresh-btn {
|
|
|
|
|
|
background: rgba(33, 150, 243, 0.8);
|
|
|
|
|
|
border-color: rgba(33, 150, 243, 0.9);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.refresh-btn:active {
|
|
|
|
|
|
background: rgba(33, 150, 243, 0.9);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 按钮图标样式 */
|
|
|
|
|
|
.btn-icon {
|
|
|
|
|
|
margin-right: 6px;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.btn-text {
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-06 15:06:48 +08:00
|
|
|
|
.loading {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 50%;
|
|
|
|
|
|
left: 50%;
|
|
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.7);
|
|
|
|
|
|
padding: 15px 30px;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
z-index: 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading::after {
|
|
|
|
|
|
content: '';
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
width: 20px;
|
|
|
|
|
|
height: 20px;
|
|
|
|
|
|
margin: 10px auto 0;
|
|
|
|
|
|
border: 3px solid rgba(255, 255, 255, 0.3);
|
|
|
|
|
|
border-top-color: white;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
animation: spin 1s linear infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes spin {
|
|
|
|
|
|
to { transform: rotate(360deg); }
|
|
|
|
|
|
}
|
2025-10-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
/* 简化的暂停占位符样式 */
|
|
|
|
|
|
.pause-placeholder {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 50%;
|
|
|
|
|
|
background: #000000;
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
z-index: 5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pause-content {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pause-title {
|
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
}
|
2025-10-06 15:06:48 +08:00
|
|
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
|
|
|
<div class="loading" id="loading">正在加载播放器...</div>
|
|
|
|
|
|
<iframe id="player-iframe" allow="autoplay; fullscreen"></iframe>
|
2025-10-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 暂停时的占位符 -->
|
|
|
|
|
|
<div class="pause-placeholder" id="pause-placeholder">
|
|
|
|
|
|
<div class="pause-content">
|
|
|
|
|
|
<div class="pause-title">监控已暂停</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 控制按钮 -->
|
|
|
|
|
|
<div class="control-buttons" id="control-buttons" style="display: none;">
|
|
|
|
|
|
<div class="control-btn play-btn" id="play-btn">
|
|
|
|
|
|
<span class="btn-icon" id="play-icon">▶️</span>
|
|
|
|
|
|
<span class="btn-text" id="play-text">播放</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="control-btn refresh-btn" id="refresh-btn">
|
|
|
|
|
|
<span class="btn-icon">🔄</span>
|
|
|
|
|
|
<span class="btn-text">刷新</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-10-06 15:06:48 +08:00
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
function log(message) {
|
|
|
|
|
|
console.log('[iframe播放器] ' + message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从URL参数获取配置
|
|
|
|
|
|
function getConfig() {
|
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
|
return {
|
|
|
|
|
|
accessToken: params.get('accessToken'),
|
|
|
|
|
|
playUrl: params.get('playUrl')
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化播放器
|
|
|
|
|
|
function init() {
|
|
|
|
|
|
log('初始化开始');
|
|
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
const configData = getConfig();
|
2025-10-06 15:06:48 +08:00
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
if (!configData.accessToken || !configData.playUrl) {
|
2025-10-06 15:06:48 +08:00
|
|
|
|
log('配置参数不完整');
|
|
|
|
|
|
document.getElementById('loading').textContent = '配置参数错误';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
// 保存配置到全局变量
|
|
|
|
|
|
config = {
|
|
|
|
|
|
accessToken: configData.accessToken,
|
|
|
|
|
|
playUrl: configData.playUrl
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-06 15:06:48 +08:00
|
|
|
|
log('AccessToken: ' + config.accessToken.substring(0, 20) + '...');
|
|
|
|
|
|
log('PlayUrl: ' + config.playUrl);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 使用萤石云官方iframe播放器(内存占用小)
|
|
|
|
|
|
const iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
|
|
|
|
|
|
'url=' + encodeURIComponent(config.playUrl) +
|
|
|
|
|
|
'&accessToken=' + encodeURIComponent(config.accessToken) +
|
|
|
|
|
|
'&width=100%' +
|
|
|
|
|
|
'&height=100%' +
|
|
|
|
|
|
'&autoplay=1' +
|
|
|
|
|
|
'&audio=1' +
|
|
|
|
|
|
'&controls=1';
|
|
|
|
|
|
|
|
|
|
|
|
log('iframe URL: ' + iframeUrl);
|
|
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
iframe.src = iframeUrl;
|
|
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
// 设置初始播放状态
|
|
|
|
|
|
isPlaying = true;
|
|
|
|
|
|
document.getElementById('play-text').textContent = '暂停';
|
|
|
|
|
|
document.getElementById('play-icon').textContent = '⏸️';
|
|
|
|
|
|
|
|
|
|
|
|
// 隐藏loading,显示控制按钮
|
2025-10-06 15:06:48 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
document.getElementById('loading').style.display = 'none';
|
2025-10-10 10:58:43 +08:00
|
|
|
|
document.getElementById('control-buttons').style.display = 'flex';
|
|
|
|
|
|
log('播放器加载完成,显示控制按钮');
|
2025-10-06 15:06:48 +08:00
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
log('初始化失败: ' + error.message);
|
|
|
|
|
|
document.getElementById('loading').textContent = '初始化失败';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 10:58:43 +08:00
|
|
|
|
// 全局状态
|
|
|
|
|
|
let isPlaying = true;
|
|
|
|
|
|
let config = null;
|
|
|
|
|
|
|
|
|
|
|
|
// 播放/暂停控制
|
|
|
|
|
|
function togglePlay() {
|
|
|
|
|
|
log('切换播放状态: ' + (isPlaying ? '暂停' : '播放'));
|
|
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
const playText = document.getElementById('play-text');
|
|
|
|
|
|
const playIcon = document.getElementById('play-icon');
|
|
|
|
|
|
const pausePlaceholder = document.getElementById('pause-placeholder');
|
|
|
|
|
|
|
|
|
|
|
|
if (isPlaying) {
|
|
|
|
|
|
// 暂停:清空iframe,显示占位符
|
|
|
|
|
|
iframe.src = 'about:blank';
|
|
|
|
|
|
pausePlaceholder.style.display = 'flex';
|
|
|
|
|
|
playText.textContent = '播放';
|
|
|
|
|
|
playIcon.textContent = '▶️';
|
|
|
|
|
|
isPlaying = false;
|
|
|
|
|
|
log('已暂停播放,显示占位符');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 播放:重新设置iframe URL,隐藏占位符
|
|
|
|
|
|
if (config) {
|
|
|
|
|
|
const iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
|
|
|
|
|
|
'url=' + encodeURIComponent(config.playUrl) +
|
|
|
|
|
|
'&accessToken=' + encodeURIComponent(config.accessToken) +
|
|
|
|
|
|
'&width=100%' +
|
|
|
|
|
|
'&height=100%' +
|
|
|
|
|
|
'&autoplay=1' +
|
|
|
|
|
|
'&audio=1' +
|
|
|
|
|
|
'&controls=1';
|
|
|
|
|
|
|
|
|
|
|
|
iframe.src = iframeUrl;
|
|
|
|
|
|
pausePlaceholder.style.display = 'none';
|
|
|
|
|
|
playText.textContent = '暂停';
|
|
|
|
|
|
playIcon.textContent = '⏸️';
|
|
|
|
|
|
isPlaying = true;
|
|
|
|
|
|
log('已开始播放,隐藏占位符');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新播放器
|
|
|
|
|
|
function refreshPlayer() {
|
|
|
|
|
|
log('刷新播放器');
|
|
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
const playText = document.getElementById('play-text');
|
|
|
|
|
|
const playIcon = document.getElementById('play-icon');
|
|
|
|
|
|
const pausePlaceholder = document.getElementById('pause-placeholder');
|
|
|
|
|
|
|
|
|
|
|
|
// 先清空,显示加载状态
|
|
|
|
|
|
iframe.src = 'about:blank';
|
|
|
|
|
|
pausePlaceholder.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟重新加载
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
if (config) {
|
|
|
|
|
|
const iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
|
|
|
|
|
|
'url=' + encodeURIComponent(config.playUrl) +
|
|
|
|
|
|
'&accessToken=' + encodeURIComponent(config.accessToken) +
|
|
|
|
|
|
'&width=100%' +
|
|
|
|
|
|
'&height=100%' +
|
|
|
|
|
|
'&autoplay=1' +
|
|
|
|
|
|
'&audio=1' +
|
|
|
|
|
|
'&controls=1';
|
|
|
|
|
|
|
|
|
|
|
|
iframe.src = iframeUrl;
|
|
|
|
|
|
playText.textContent = '暂停';
|
|
|
|
|
|
playIcon.textContent = '⏸️';
|
|
|
|
|
|
isPlaying = true;
|
|
|
|
|
|
log('刷新完成');
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 500);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-06 15:06:48 +08:00
|
|
|
|
// 页面加载完成后初始化
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
|
|
log('页面加载完成');
|
2025-10-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
// 绑定按钮事件
|
|
|
|
|
|
document.getElementById('play-btn').addEventListener('click', togglePlay);
|
|
|
|
|
|
document.getElementById('refresh-btn').addEventListener('click', refreshPlayer);
|
|
|
|
|
|
|
2025-10-06 15:06:48 +08:00
|
|
|
|
init();
|
|
|
|
|
|
};
|
2025-10-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
// 页面卸载时清理资源
|
|
|
|
|
|
window.onbeforeunload = function() {
|
|
|
|
|
|
log('页面即将卸载,清理播放器资源');
|
|
|
|
|
|
try {
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
if (iframe) {
|
|
|
|
|
|
iframe.src = 'about:blank'; // 清空iframe源
|
|
|
|
|
|
log('播放器资源已清理');
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
log('清理播放器资源失败: ' + error.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 页面隐藏时暂停播放
|
|
|
|
|
|
document.addEventListener('visibilitychange', function() {
|
|
|
|
|
|
if (document.hidden) {
|
|
|
|
|
|
log('页面隐藏,暂停播放');
|
|
|
|
|
|
try {
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
if (iframe) {
|
|
|
|
|
|
iframe.style.display = 'none';
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
log('暂停播放失败: ' + error.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log('页面显示,恢复播放');
|
|
|
|
|
|
try {
|
|
|
|
|
|
const iframe = document.getElementById('player-iframe');
|
|
|
|
|
|
if (iframe) {
|
|
|
|
|
|
iframe.style.display = 'block';
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
log('恢复播放失败: ' + error.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-10-06 15:06:48 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
</html>
|
|
|
|
|
|
|