萧乐乐 发表于 前天 19:04

《射雕英雄传》四十二集电视连续剧[李亚鹏周迅版]

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Discuz M3U8 分集播放器</title>
    <!-- 引入 TailwindCSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
      tailwind.config = {
      corePlugins: {
      preflight: false, // 关闭Tailwind的全局重置样式,避免覆盖Discuz原有页面样式
                     }
      }
    </script>
    <!-- 引入 Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- 引入 Hls.js -->
    <script src="https://cdn.jsdelivr.net/npm/hls.js@latest/dist/hls.min.js"></script>
    <style>
      /* 自定义滚动条样式 */
      .episode-scroll::-webkit-scrollbar {
            width: 6px;
            height: 6px;
      }
      .episode-scroll::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 3px;
      }
      .episode-scroll::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 3px;
      }
      .episode-scroll::-webkit-scrollbar-thumb:hover {
            background: #94a3b8;
      }
      /* 选中状态动画 */
      .episode-btn.active {
            background-color: #3b82f6;
            color: white;
            border-color: #3b82f6;
      }
      /* 加载动画 */
      .loader {
            border: 3px solid #f3f3f3;
            border-radius: 50%;
            border-top: 3px solid #3b82f6;
            width: 24px;
            height: 24px;
            -webkit-animation: spin 1s linear infinite; /* Safari */
            animation: spin 1s linear infinite;
      }
      @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
      }
    </style>
</head>
<body class="bg-gray-100 p-4 font-sans">

    <!-- 播放器容器 -->
    <div id="dz-video-player-container" class="max-w-4xl mx-auto bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200" style="isolation: isolate;">
      
      <!-- 视频区域 -->
      <div class="relative w-full aspect-video bg-black group">
            <video id="dz-video-element" class="w-full h-full object-contain" controls playsinline poster="/data/attachment/album/202608/31/200711vfnhzq7opn8dqp00.jpg"></video>
            
            <!-- 加载指示器 -->
            <div id="dz-loading-indicator" class="absolute inset-0 flex items-center justify-center bg-black/50 hidden z-10">
                <div class="loader"></div>
            </div>

            <!-- 错误提示层 -->
            <div id="dz-error-overlay" class="absolute inset-0 flex flex-col items-center justify-center bg-black/80 text-white hidden z-20">
                <i class="fas fa-exclamation-triangle text-4xl mb-2 text-red-500"></i>
                <p class="text-sm">视频加载失败,请检查网络或链接有效性</p>
                <button onclick="retryLoad()" class="mt-4 px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded text-sm transition">重试</button>
            </div>
      </div>

      <!-- 控制面板:标题与分集 -->
      <div class="p-4 bg-white">
            <div class="flex justify-between items-center mb-4 border-b pb-2">
                <h2 id="dz-video-title" class="text-lg font-bold text-gray-800 truncate pr-4">正在播放:第 1 集</h2>
                <!-- div class="text-xs text-gray-500 flex items-center gap-2">
                  <span id="dz-quality-badge" class="px-2 py-1 bg-gray-100 rounded text-gray-600">HD</span>
                  <span id="dz-duration">00:00</span>
                </div -->
            </div>

            <!-- 分集列表 -->
            <div class="mb-2 flex justify-between items-center">
                <span class="text-sm font-semibold text-gray-700"><i class="fas fa-list-ul mr-1"></i> 选集</span>
                <div class="flex gap-2">
                     <button onclick="toggleOrder()" class="text-xs text-blue-600 hover:text-blue-800 flex items-center gap-1">
                        <i class="fas fa-sort-amount-down" id="sort-icon"></i> <span id="sort-text">倒序</span>
                  </button>
                </div>
            </div>
            
            <div id="dz-episode-list" class="grid grid-cols-4 sm:grid-cols-6 md:grid-cols-8 gap-2 max-h-40 overflow-y-auto episode-scroll p-1">
                <!-- 分集按钮将通过 JS 动态生成 -->
            </div>
      </div>
    </div>

    <script>
      /**
         * Discuz M3U8 Player Configuration
         * 在 Discuz 发帖时,只需修改此处的 videoData 数组即可
         */
      const videoData = [
            { title: "第01集", url: "https://vip.lz-cdn6.com/20220906/26768_bf27aba1/1000k/hls/mixed.m3u8"},
            { title: "第02集", url: "https://vip.lz-cdn6.com/20220906/26769_20cc5224/1000k/hls/mixed.m3u8"},
            { title: "第03集", url: "https://vip.lz-cdn6.com/20220906/26770_92ae2423/1000k/hls/mixed.m3u8"},
            { title: "第04集", url: "https://vip.lz-cdn6.com/20220906/26771_ae996dbb/1000k/hls/mixed.m3u8"},
            { title: "第05集", url: "https://vip.lz-cdn6.com/20220906/26772_ec0a7951/1000k/hls/mixed.m3u8"},
            { title: "第06集", url: "https://vip.lz-cdn6.com/20220906/26773_5ff380cb/1000k/hls/mixed.m3u8"},
            { title: "第07集", url: "https://vip.lz-cdn6.com/20220906/26774_cd714194/1000k/hls/mixed.m3u8"},
            { title: "第08集", url: "https://vip.lz-cdn6.com/20220906/26775_9cfd72e9/1000k/hls/mixed.m3u8"},
            { title: "第09集", url: "https://vip.lz-cdn6.com/20220906/26776_33375fcf/1000k/hls/mixed.m3u8"},
            { title: "第10集", url: "https://vip.lz-cdn6.com/20220906/26777_e2391921/1000k/hls/mixed.m3u8"},
            { title: "第11集", url: "https://vip.lz-cdn6.com/20220906/26778_a8f08c46/1000k/hls/mixed.m3u8"},
            { title: "第12集", url: "https://vip.lz-cdn6.com/20220906/26779_63f37925/1000k/hls/mixed.m3u8"},
            { title: "第13集", url: "https://vip.lz-cdn6.com/20220906/26780_cff0a918/1000k/hls/mixed.m3u8"},
            { title: "第14集", url: "https://vip.lz-cdn6.com/20220906/26781_4f062318/1000k/hls/mixed.m3u8"},
            { title: "第15集", url: "https://vip.lz-cdn6.com/20220906/26782_aa86b24d/1000k/hls/mixed.m3u8"},
            { title: "第16集", url: "https://vip.lz-cdn6.com/20220906/26783_836c3f5c/1000k/hls/mixed.m3u8"},
            { title: "第17集", url: "https://vip.lz-cdn6.com/20220906/26784_b89949bf/1000k/hls/mixed.m3u8"},
            { title: "第18集", url: "https://vip.lz-cdn6.com/20220906/26785_f881bfc5/1000k/hls/mixed.m3u8"},
            { title: "第19集", url: "https://vip.lz-cdn6.com/20220906/26786_206dc997/1000k/hls/mixed.m3u8"},
            { title: "第20集", url: "https://vip.lz-cdn6.com/20220906/26787_5bbb479f/1000k/hls/mixed.m3u8"},
            { title: "第21集", url: "https://vip.lz-cdn6.com/20220906/26788_009396cb/1000k/hls/mixed.m3u8"},
            { title: "第22集", url: "https://vip.lz-cdn6.com/20220906/26789_f8f61f82/1000k/hls/mixed.m3u8"},
            { title: "第23集", url: "https://vip.lz-cdn6.com/20220906/26790_ed4a36bc/1000k/hls/mixed.m3u8"},
            { title: "第24集", url: "https://vip.lz-cdn6.com/20220906/26791_283d068e/1000k/hls/mixed.m3u8"},
            { title: "第25集", url: "https://vip.lz-cdn6.com/20220906/26792_3b27519a/1000k/hls/mixed.m3u8"},
            { title: "第26集", url: "https://vip.lz-cdn6.com/20220906/26793_fe41c14e/1000k/hls/mixed.m3u8"},
            { title: "第27集", url: "https://vip.lz-cdn6.com/20220906/26794_3dd0f9e6/1000k/hls/mixed.m3u8"},
            { title: "第28集", url: "https://vip.lz-cdn6.com/20220906/26795_d5fdbcaf/1000k/hls/mixed.m3u8"},
            { title: "第29集", url: "https://vip.lz-cdn6.com/20220906/26796_ce718139/1000k/hls/mixed.m3u8"},
            { title: "第30集", url: "https://vip.lz-cdn6.com/20220906/26797_082e2ccf/1000k/hls/mixed.m3u8"},
            { title: "第31集", url: "https://vip.lz-cdn6.com/20220906/26798_d0983854/1000k/hls/mixed.m3u8"},
            { title: "第32集", url: "https://vip.lz-cdn6.com/20220906/26799_489aaee0/1000k/hls/mixed.m3u8"},
            { title: "第33集", url: "https://vip.lz-cdn6.com/20220906/26800_c1eed324/1000k/hls/mixed.m3u8"},
            { title: "第34集", url: "https://vip.lz-cdn6.com/20220906/26801_ec40874c/1000k/hls/mixed.m3u8"},
            { title: "第35集", url: "https://vip.lz-cdn6.com/20220907/26802_52bb9be9/1000k/hls/mixed.m3u8"},
            { title: "第36集", url: "https://vip.lz-cdn6.com/20220907/26803_62ccd5b3/1000k/hls/mixed.m3u8"},
            { title: "第37集", url: "https://vip.lz-cdn6.com/20220907/26804_56a5e927/1000k/hls/mixed.m3u8"},
            { title: "第38集", url: "https://vip.lz-cdn6.com/20220907/26805_a54f39ce/1000k/hls/mixed.m3u8"},
            { title: "第39集", url: "https://vip.lz-cdn6.com/20220907/26806_b480d476/1000k/hls/mixed.m3u8"},
            { title: "第40集", url: "https://vip.lz-cdn6.com/20220907/26807_b2fb7cdb/1000k/hls/mixed.m3u8"},
            { title: "第41集", url: "https://vip.lz-cdn6.com/20220907/26808_769664f8/1000k/hls/mixed.m3u8"},
            { title: "第42集", url: "https://vip.lz-cdn6.com/20220907/26809_196835e4/1000k/hls/mixed.m3u8"}
      ];

      // 全局变量
      let hls = null;
      let currentEpisodeIndex = 0;
      let isReversed = false;
      let displayedData = [...videoData];
      const videoElement = document.getElementById('dz-video-element');
      const episodeListContainer = document.getElementById('dz-episode-list');
      const loadingIndicator = document.getElementById('dz-loading-indicator');
      const errorOverlay = document.getElementById('dz-error-overlay');
      const titleElement = document.getElementById('dz-video-title');
      const durationElement = document.getElementById('dz-duration');

      /**
         * 初始化播放器
         */
      function initPlayer() {
            renderEpisodes();
            loadEpisode(0); // 默认加载第一集
            
            // 监听视频元数据加载完成,更新时长显示
            videoElement.addEventListener('loadedmetadata', () => {
                durationElement.innerText = formatTime(videoElement.duration);
            });

            // 监听播放结束,自动下一集
            videoElement.addEventListener('ended', () => {
                playNext();
            });
      }

      /**
         * 渲染分集列表
         */
      function renderEpisodes() {
            episodeListContainer.innerHTML = '';
            displayedData.forEach((item, index) => {
                // 找到原始数据中的真实索引,用于点击事件
                const originalIndex = videoData.indexOf(item);
               
                const btn = document.createElement('button');
                btn.className = `episode-btn px-3 py-2 text-xs font-medium rounded border border-gray-200 text-gray-700 hover:bg-blue-50 hover:border-blue-200 transition-all truncate ${originalIndex === currentEpisodeIndex ? 'active' : ''}`;
                btn.innerText = item.title;
                btn.onclick = () => loadEpisode(originalIndex);
                episodeListContainer.appendChild(btn);
            });
      }

      /**
         * 加载指定集数
         * @param {number} index - 原始数据数组中的索引
         */
      function loadEpisode(index) {
            if (index < 0 || index >= videoData.length) return;

            currentEpisodeIndex = index;
            const data = videoData;
            
            // 更新UI状态
            updateActiveButton();
            titleElement.innerText = `正在播放:${data.title}`;
            showLoading(true);
            hideError();

            // 销毁旧的 HLS 实例
            if (hls) {
                hls.destroy();
            }

            // 创建新的 HLS 实例
            if (Hls.isSupported()) {
                hls = new Hls({
                  debug: false,
                  enableWorker: true,
                  lowLatencyMode: true,
                  backBufferLength: 90
                });

                hls.loadSource(data.url);
                hls.attachMedia(videoElement);

                hls.on(Hls.Events.MANIFEST_PARSED, function() {
                  videoElement.play().catch(e => console.log("Auto-play prevented:", e));
                  showLoading(false);
                });

                hls.on(Hls.Events.ERROR, function(event, data) {
                  if (data.fatal) {
                        switch(data.type) {
                            case Hls.ErrorTypes.NETWORK_ERROR:
                              console.log("fatal network error encountered, try to recover");
                              hls.startLoad();
                              break;
                            case Hls.ErrorTypes.MEDIA_ERROR:
                              console.log("fatal media error encountered, try to recover");
                              hls.recoverMediaError();
                              break;
                            default:
                              showError();
                              hls.destroy();
                              break;
                        }
                  }
                });

            } else if (videoElement.canPlayType('application/vnd.apple.mpegurl')) {
                // Safari 原生支持
                videoElement.src = data.url;
                videoElement.addEventListener('loadedmetadata', function() {
                  videoElement.play();
                  showLoading(false);
                });
            } else {
                showError();
            }
      }

      /**
         * 更新按钮激活状态
         */
      function updateActiveButton() {
            const buttons = episodeListContainer.querySelectorAll('.episode-btn');
            buttons.forEach((btn, idx) => {
                // 注意:displayedData 可能是反转的,所以需要比对内容或重新映射
                // 这里简单起见,我们重新渲染或者通过文本匹配,但更优解是重新渲染
                // 为了性能,我们直接重新渲染整个列表是最安全的,因为列表通常不长
                renderEpisodes();
            });
      }

      /**
         * 播放下一集
         */
      function playNext() {
            if (currentEpisodeIndex < videoData.length - 1) {
                loadEpisode(currentEpisodeIndex + 1);
                // 滚动到当前选中的按钮
                setTimeout(() => {
                  const activeBtn = document.querySelector('.episode-btn.active');
                  if(activeBtn) activeBtn.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
                }, 100);
            }
      }

      /**
         * 切换排序(正序/倒序)
         */
      function toggleOrder() {
            isReversed = !isReversed;
            const sortIcon = document.getElementById('sort-icon');
            const sortText = document.getElementById('sort-text');
            
            if (isReversed) {
                displayedData = [...videoData].reverse();
                sortIcon.className = "fas fa-sort-amount-up";
                sortText.innerText = "正序";
            } else {
                displayedData = [...videoData];
                sortIcon.className = "fas fa-sort-amount-down";
                sortText.innerText = "倒序";
            }
            renderEpisodes();
      }

      /**
         * 重试加载
         */
      function retryLoad() {
            loadEpisode(currentEpisodeIndex);
      }

      /**
         * UI 辅助函数
         */
      function showLoading(show) {
            loadingIndicator.classList.toggle('hidden', !show);
      }

      function showError() {
            errorOverlay.classList.remove('hidden');
            showLoading(false);
      }

      function hideError() {
            errorOverlay.classList.add('hidden');
      }

      function formatTime(seconds) {
            if (isNaN(seconds)) return "00:00";
            const m = Math.floor(seconds / 60);
            const s = Math.floor(seconds % 60);
            return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
      }

      // 启动
      document.addEventListener('DOMContentLoaded', initPlayer);

    </script>
</body>
</html>
页: [1]
查看完整版本: 《射雕英雄传》四十二集电视连续剧[李亚鹏周迅版]