Unify web player controls and add volume control

This commit is contained in:
2026-04-22 10:45:46 +08:00
parent 6eb0baf16e
commit 425ea363f8
6 changed files with 124 additions and 4 deletions

View File

@@ -45,14 +45,21 @@
<script src="flv.min.js"></script>
</head>
<body>
<video id="player" controls autoplay muted playsinline></video>
<video id="player" autoplay muted playsinline></video>
<div id="message">Loading live stream...</div>
<script>
const params = new URLSearchParams(window.location.search);
const streamUrl = params.get('src');
const initialVolume = Number.parseFloat(params.get('volume') || '1');
const video = document.getElementById('player');
const message = document.getElementById('message');
function applyVolume(value) {
const normalized = Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 1;
video.volume = normalized;
video.muted = normalized === 0;
}
function showMessage(text) {
video.style.display = 'none';
message.style.display = 'flex';
@@ -66,6 +73,8 @@
} else if (!flvjs.isSupported()) {
showMessage('This browser does not support FLV playback.');
} else {
applyVolume(initialVolume);
const player = flvjs.createPlayer({
type: 'flv',
url: streamUrl,
@@ -90,6 +99,13 @@
video.style.display = 'block';
message.style.display = 'none';
window.addEventListener('message', function(event) {
const data = event.data || {};
if (data.type === 'setVolume') {
applyVolume(Number(data.value));
}
});
window.addEventListener('beforeunload', function() {
player.destroy();
});