wenhongquan 1 өдөр өмнө
parent
commit
641c2b105e

+ 18 - 1
video_manager.html

@@ -4,6 +4,11 @@
     <meta charset="UTF-8">
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>RTSP视频流管理系统</title>
     <title>RTSP视频流管理系统</title>
+    <!-- 
+        自定义API基础URL(可选):
+        <script>window.API_BASE_URL = 'http://your-custom-domain:port';</script>
+        如果不设置,将自动使用当前页面的域名和端口
+    -->
     <style>
     <style>
         * {
         * {
             margin: 0;
             margin: 0;
@@ -393,7 +398,19 @@
     </div>
     </div>
 
 
     <script>
     <script>
-        const API_BASE = 'http://localhost:8080';
+        // 动态获取API基础URL,支持不同环境部署
+        function getApiBase() {
+            // 优先使用环境变量或配置
+            if (window.API_BASE_URL) {
+                return window.API_BASE_URL;
+            }
+            
+            // 默认使用当前页面的主机和端口
+            return `${window.location.protocol}//${window.location.host}`;
+        }
+        
+        const API_BASE = getApiBase();
+        console.log('当前 API 基础URL:', API_BASE);
 
 
         function switchTab(tab) {
         function switchTab(tab) {
             document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
             document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));

+ 24 - 1
video_test.html

@@ -2,19 +2,42 @@
 <html>
 <html>
 <head>
 <head>
     <title>视频播放测试</title>
     <title>视频播放测试</title>
+    <!-- 
+        自定义API基础URL(可选):
+        <script>window.API_BASE_URL = 'http://your-custom-domain:port';</script>
+        如果不设置,将自动使用当前页面的域名和端口
+    -->
 </head>
 </head>
 <body>
 <body>
     <h1>视频播放测试</h1>
     <h1>视频播放测试</h1>
     
     
     <video width="640" height="480" controls>
     <video width="640" height="480" controls>
-        <source src="http://localhost:8080/videos/20251010_160000/test_stream1.mp4" type="video/mp4">
+        <source id="video-source" src="" type="video/mp4">
         您的浏览器不支持视频播放。
         您的浏览器不支持视频播放。
     </video>
     </video>
     
     
     <script>
     <script>
+        // 动态获取API基础URL,支持不同环境部署
+        function getApiBase() {
+            // 优先使用环境变量或配置
+            if (window.API_BASE_URL) {
+                return window.API_BASE_URL;
+            }
+            
+            // 默认使用当前页面的主机和端口
+            return `${window.location.protocol}//${window.location.host}`;
+        }
+        
+        const API_BASE = getApiBase();
+        console.log('当前 API 基础URL:', API_BASE);
+        
+        // 设置视频源
+        document.getElementById('video-source').src = `${API_BASE}/videos/20251010_160000/test_stream1.mp4`;
+        
         const video = document.querySelector('video');
         const video = document.querySelector('video');
         video.addEventListener('error', (e) => {
         video.addEventListener('error', (e) => {
             console.log('视频加载错误:', e);
             console.log('视频加载错误:', e);
+            console.log('尝试的URL:', e.target.src);
         });
         });
         video.addEventListener('loadstart', () => {
         video.addEventListener('loadstart', () => {
             console.log('开始加载视频');
             console.log('开始加载视频');