116 lines
3.4 KiB
HTML
116 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>多音轨 HLS 测试</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
video {
|
|
width: 100%;
|
|
max-width: 800px;
|
|
height: auto;
|
|
}
|
|
|
|
.controls {
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.audio-tracks {
|
|
margin: 10px 0;
|
|
}
|
|
|
|
.audio-tracks label {
|
|
display: block;
|
|
margin: 5px 0;
|
|
}
|
|
|
|
.info {
|
|
background: #f5f5f5;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
margin: 20px 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>多音轨 HLS 视频播放器测试</h1>
|
|
|
|
<video id="video" controls></video>
|
|
|
|
<div class="controls">
|
|
<div class="audio-tracks">
|
|
<h3>音轨选择:</h3>
|
|
<div id="audioTracks"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="info">
|
|
<h3>说明:</h3>
|
|
<p>此页面用于测试从 merged_dual_track.mp4 生成的多音轨 HLS 流</p>
|
|
<p>HLS 主播放列表: <code>hls_output/master.m3u8</code></p>
|
|
<p>包含两个音轨:Audio Track 1 (默认) 和 Audio Track 2</p>
|
|
</div>
|
|
|
|
<script>
|
|
const video = document.getElementById('video');
|
|
const audioTracksDiv = document.getElementById('audioTracks');
|
|
|
|
if (Hls.isSupported()) {
|
|
const hls = new Hls();
|
|
hls.loadSource('hls_output/master.m3u8');
|
|
hls.attachMedia(video);
|
|
|
|
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
|
console.log('HLS manifest parsed');
|
|
console.log('Audio tracks:', hls.audioTracks);
|
|
updateAudioTrackControls(hls);
|
|
});
|
|
|
|
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, function () {
|
|
console.log('Audio tracks updated');
|
|
updateAudioTrackControls(hls);
|
|
});
|
|
|
|
function updateAudioTrackControls(hls) {
|
|
audioTracksDiv.innerHTML = '';
|
|
|
|
hls.audioTracks.forEach((track, index) => {
|
|
const label = document.createElement('label');
|
|
const radio = document.createElement('input');
|
|
radio.type = 'radio';
|
|
radio.name = 'audioTrack';
|
|
radio.value = index;
|
|
radio.checked = index === hls.audioTrack;
|
|
|
|
radio.addEventListener('change', function () {
|
|
if (this.checked) {
|
|
hls.audioTrack = parseInt(this.value);
|
|
console.log('Switched to audio track:', track);
|
|
}
|
|
});
|
|
|
|
label.appendChild(radio);
|
|
label.appendChild(document.createTextNode(` ${track.name || `Audio Track ${index + 1}`}`));
|
|
audioTracksDiv.appendChild(label);
|
|
});
|
|
}
|
|
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
// 原生 HLS 支持 (Safari)
|
|
video.src = 'hls_output/master.m3u8';
|
|
} else {
|
|
alert('您的浏览器不支持 HLS 播放');
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |