盘基地资源论坛

 找回密码
 立即注册
搜索
热搜: 书籍 电影 音乐
查看: 14|回复: 0

Java网页m3u流媒体播放器代码

[复制链接]

963

主题

153

回帖

4301

积分

中级会员

Rank: 3Rank: 3

UID
32013
金钱
3178
钻石
7
积分
4301
注册时间
2023-7-27
发表于 3 天前 | 显示全部楼层 |阅读模式
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>16:9 Window with HLS.js</title>
  7.     <style>
  8.         html, body {
  9.             height: 100%;
  10.             margin: 0;
  11.             padding: 0;
  12.             overflow: hidden;
  13.         }
  14.         .container {
  15.             display: flex;
  16.             height: 100%;
  17.         }
  18.         .video-container {
  19.             flex: 1;
  20.             background-color: #000000; /* 黑色背景 */
  21.             display: flex;
  22.             justify-content: center;
  23.             align-items: center;
  24.         }
  25.         .program-list {
  26.             width: 200px;
  27.             background-color: #000; /* 黑色背景 */
  28.             opacity: 0.8; /* 透明度 */
  29.             overflow-y: auto;
  30.             padding: 10px;
  31.             transition: width 0.3s ease;
  32.         }
  33.         .program-list.collapsed {
  34.             width: 0;
  35.             padding: 0;
  36.             overflow: hidden;
  37.         }
  38.         video {
  39.             width: 100%;
  40.             height: 100%;
  41.         }
  42.         .program-list ul {
  43.             list-style-type: none;
  44.             padding: 0;
  45.             margin: 0;
  46.         }
  47.         .program-list li {
  48.             padding: 5px;
  49.             cursor: pointer;
  50.         }
  51.         .program-list li:hover {
  52.             background-color: #ddd;
  53.         }
  54.         .toggle-button {
  55.             position: absolute;
  56.             top: 10px;
  57.             right: 10px;
  58.             cursor: pointer;
  59.             background-color: #000;
  60.             color: #fff;
  61.             padding: 5px 10px;
  62.             border-radius: 5px;
  63.         }
  64.         .search-box {
  65.             margin: 10px;
  66.         }
  67.         .search-box input {
  68.             width: 100%;
  69.             padding: 10px;
  70.             box-sizing: border-box;
  71.         }
  72.         .play-prompt {
  73.             position: absolute;
  74.             top: 50%;
  75.             left: 50%;
  76.             transform: translate(-50%, -50%);
  77.             color: white;
  78.             font-size: 24px;
  79.             cursor: pointer;
  80.             background-color: rgba(0, 0, 0, 0.5);
  81.             padding: 10px 20px;
  82.             border-radius: 5px;
  83.         }
  84.     </style>
  85. </head>
  86. <body>
  87.     <div class="container">
  88.         <div class="video-container" id="fullscreenWindow">
  89.             <!-- 视频播放器容器 -->
  90.             <video id="video" controls></video>
  91.             <div class="play-prompt" onclick="startPlayback()">点击播放</div>
  92.         </div>
  93.         <div class="program-list" id="programList">
  94.             <div class="search-box">
  95.                 <input type="text" id="m3uUrl" placeholder="粘贴 M3U 链接">
  96.                 <button onclick="loadM3UFile()">播放</button>
  97.             </div>
  98.             <ul>
  99.                 <!-- 节目列表项将动态添加到这里 -->
  100.             </ul>
  101.         </div>
  102.     </div>
  103.     <div class="toggle-button" id="toggleButton">
  104.         &#9776;
  105.     </div>

  106.     <!-- 引入 HLS.js 库 -->
  107.     <script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.0.11/hls.min.js"></script>

  108.     <script>
  109.         // 获取视频元素
  110.         var video = document.getElementById('video');
  111.         var playPrompt = document.querySelector('.play-prompt');

  112.         // 检查浏览器是否支持 HLS
  113.         if (Hls.isSupported()) {
  114.             var hls = new Hls();
  115.             hls.attachMedia(video);
  116.             hls.on(Hls.Events.MANIFEST_PARSED, function() {
  117.                 console.log('Manifest parsed, ready to play');
  118.                 playPrompt.style.display = 'block';
  119.             });
  120.             hls.on(Hls.Events.ERROR, function(event, data) {
  121.                 console.error('HLS error', data);
  122.             });
  123.         } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  124.             video.addEventListener('loadedmetadata', function() {
  125.                 console.log('Metadata loaded, ready to play');
  126.                 playPrompt.style.display = 'block';
  127.             });
  128.         } else {
  129.             console.error('HLS is not supported');
  130.         }

  131.         // 获取节目列表元素
  132.         var programList = document.getElementById('programList');
  133.         var toggleButton = document.getElementById('toggleButton');

  134.         // 切换节目列表的显示状态
  135.         toggleButton.addEventListener('click', function() {
  136.             programList.classList.toggle('collapsed');
  137.         });

  138.         // 加载 M3U 文件并解析节目列表
  139.         function loadM3UFile() {
  140.             const m3uUrl = document.getElementById('m3uUrl').value;
  141.             if (m3uUrl) {
  142.                 if (Hls.isSupported()) {
  143.                     hls.loadSource(m3uUrl);
  144.                 } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  145.                     video.src = m3uUrl;
  146.                 } else {
  147.                     console.error('HLS is not supported');
  148.                 }
  149.             } else {
  150.                 console.error('No M3U URL provided');
  151.             }
  152.         }

  153.         // 页面加载完成后获取 M3U 文件并解析节目列表
  154.         document.addEventListener('DOMContentLoaded', function() {
  155.             const m3uUrl = 'https://super.ffzy-online6.com/20240626/33675_8de06b98/2000k/hls/mixed.m3u8'; // 默认 M3U 链接
  156.             document.getElementById('m3uUrl').value = m3uUrl;
  157.             loadM3UFile();
  158.         });

  159.         // 用户点击提示后开始播放
  160.         function startPlayback() {
  161.             video.play().then(() => {
  162.                 playPrompt.style.display = 'none';
  163.             }).catch(error => {
  164.                 console.error('Playback failed', error);
  165.             });
  166.         }

  167.         document.getElementById('fullscreenWindow').addEventListener('dblclick', function() {
  168.             if (document.fullscreenElement) {
  169.                 if (document.exitFullscreen) {
  170.                     document.exitFullscreen();
  171.                 } else if (document.mozCancelFullScreen) { // Firefox
  172.                     document.mozCancelFullScreen();
  173.                 } else if (document.webkitExitFullscreen) { // Chrome, Safari and Opera
  174.                     document.webkitExitFullscreen();
  175.                 } else if (document.msExitFullscreen) { // IE/Edge
  176.                     document.msExitFullscreen();
  177.                 }
  178.             } else {
  179.                 var elem = document.getElementById('fullscreenWindow');
  180.                 if (elem.requestFullscreen) {
  181.                     elem.requestFullscreen();
  182.                 } else if (elem.mozRequestFullScreen) { // Firefox
  183.                     elem.mozRequestFullScreen();
  184.                 } else if (elem.webkitRequestFullscreen) { // Chrome, Safari and Opera
  185.                     elem.webkitRequestFullscreen();
  186.                 } else if (elem.msRequestFullscreen) { // IE/Edge
  187.                     elem.msRequestFullscreen();
  188.                 }
  189.             }
  190.         });
  191.     </script>
  192. </body>
  193. </html>
复制代码


盘基地论坛免责声明
1、本站资源来自互联网用户收集发布,仅供用于学习和交流。
2、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。
3、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决。
4、联系邮箱:[email protected]
5、官方网址:www.panjdzy.com
6、备用网址:www.panjd.top




上一篇:JavaFX SDK相关配置
下一篇:Java视频播放器代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

论坛新闻X


  扫码关注左侧公号,每月定期发送扩容福利码。

...

查看详情

Archiver|手机版|小黑屋|盘基地资源论坛

GMT+8, 2024-6-30 09:40 , Processed in 0.074233 second(s), 23 queries .

Powered by Discuz!

本站资源来自互联网用户收集发布,仅供用于学习和交流。

如有侵权之处,请联系站长并出示版权证明以便删除,敬请谅解!

联系邮箱:[email protected]

快速回复 返回顶部 返回列表