|
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>16:9 Window with HLS.js</title>
- <style>
- html, body {
- height: 100%;
- margin: 0;
- padding: 0;
- overflow: hidden;
- }
- .container {
- display: flex;
- height: 100%;
- }
- .video-container {
- flex: 1;
- background-color: #000000; /* 黑色背景 */
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .program-list {
- width: 200px;
- background-color: #000; /* 黑色背景 */
- opacity: 0.8; /* 透明度 */
- overflow-y: auto;
- padding: 10px;
- transition: width 0.3s ease;
- }
- .program-list.collapsed {
- width: 0;
- padding: 0;
- overflow: hidden;
- }
- video {
- width: 100%;
- height: 100%;
- }
- .program-list ul {
- list-style-type: none;
- padding: 0;
- margin: 0;
- }
- .program-list li {
- padding: 5px;
- cursor: pointer;
- }
- .program-list li:hover {
- background-color: #ddd;
- }
- .toggle-button {
- position: absolute;
- top: 10px;
- right: 10px;
- cursor: pointer;
- background-color: #000;
- color: #fff;
- padding: 5px 10px;
- border-radius: 5px;
- }
- .search-box {
- margin: 10px;
- }
- .search-box input {
- width: 100%;
- padding: 10px;
- box-sizing: border-box;
- }
- .play-prompt {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- color: white;
- font-size: 24px;
- cursor: pointer;
- background-color: rgba(0, 0, 0, 0.5);
- padding: 10px 20px;
- border-radius: 5px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="video-container" id="fullscreenWindow">
- <!-- 视频播放器容器 -->
- <video id="video" controls></video>
- <div class="play-prompt" onclick="startPlayback()">点击播放</div>
- </div>
- <div class="program-list" id="programList">
- <div class="search-box">
- <input type="text" id="m3uUrl" placeholder="粘贴 M3U 链接">
- <button onclick="loadM3UFile()">播放</button>
- </div>
- <ul>
- <!-- 节目列表项将动态添加到这里 -->
- </ul>
- </div>
- </div>
- <div class="toggle-button" id="toggleButton">
- ☰
- </div>
- <!-- 引入 HLS.js 库 -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.0.11/hls.min.js"></script>
- <script>
- // 获取视频元素
- var video = document.getElementById('video');
- var playPrompt = document.querySelector('.play-prompt');
- // 检查浏览器是否支持 HLS
- if (Hls.isSupported()) {
- var hls = new Hls();
- hls.attachMedia(video);
- hls.on(Hls.Events.MANIFEST_PARSED, function() {
- console.log('Manifest parsed, ready to play');
- playPrompt.style.display = 'block';
- });
- hls.on(Hls.Events.ERROR, function(event, data) {
- console.error('HLS error', data);
- });
- } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
- video.addEventListener('loadedmetadata', function() {
- console.log('Metadata loaded, ready to play');
- playPrompt.style.display = 'block';
- });
- } else {
- console.error('HLS is not supported');
- }
- // 获取节目列表元素
- var programList = document.getElementById('programList');
- var toggleButton = document.getElementById('toggleButton');
- // 切换节目列表的显示状态
- toggleButton.addEventListener('click', function() {
- programList.classList.toggle('collapsed');
- });
- // 加载 M3U 文件并解析节目列表
- function loadM3UFile() {
- const m3uUrl = document.getElementById('m3uUrl').value;
- if (m3uUrl) {
- if (Hls.isSupported()) {
- hls.loadSource(m3uUrl);
- } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
- video.src = m3uUrl;
- } else {
- console.error('HLS is not supported');
- }
- } else {
- console.error('No M3U URL provided');
- }
- }
- // 页面加载完成后获取 M3U 文件并解析节目列表
- document.addEventListener('DOMContentLoaded', function() {
- const m3uUrl = 'https://super.ffzy-online6.com/20240626/33675_8de06b98/2000k/hls/mixed.m3u8'; // 默认 M3U 链接
- document.getElementById('m3uUrl').value = m3uUrl;
- loadM3UFile();
- });
- // 用户点击提示后开始播放
- function startPlayback() {
- video.play().then(() => {
- playPrompt.style.display = 'none';
- }).catch(error => {
- console.error('Playback failed', error);
- });
- }
- document.getElementById('fullscreenWindow').addEventListener('dblclick', function() {
- if (document.fullscreenElement) {
- if (document.exitFullscreen) {
- document.exitFullscreen();
- } else if (document.mozCancelFullScreen) { // Firefox
- document.mozCancelFullScreen();
- } else if (document.webkitExitFullscreen) { // Chrome, Safari and Opera
- document.webkitExitFullscreen();
- } else if (document.msExitFullscreen) { // IE/Edge
- document.msExitFullscreen();
- }
- } else {
- var elem = document.getElementById('fullscreenWindow');
- if (elem.requestFullscreen) {
- elem.requestFullscreen();
- } else if (elem.mozRequestFullScreen) { // Firefox
- elem.mozRequestFullScreen();
- } else if (elem.webkitRequestFullscreen) { // Chrome, Safari and Opera
- elem.webkitRequestFullscreen();
- } else if (elem.msRequestFullscreen) { // IE/Edge
- elem.msRequestFullscreen();
- }
- }
- });
- </script>
- </body>
- </html>
复制代码
|
盘基地论坛免责声明
1、本站资源来自互联网用户收集发布,仅供用于学习和交流。
2、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。
3、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决。
4、联系邮箱:admin@panjdzy.com
5、官方网址:www.panjdzy.com
6、备用网址:www.panjd.top
上一篇:JavaFX SDK相关配置下一篇:Java视频播放器代码
|