119 lines
3.3 KiB
HTML
Raw Normal View History

2024-12-12 10:28:03 +08:00
<!DOCTYPE html>
<html lang="en">
2025-04-18 10:33:51 +08:00
2024-12-12 10:28:03 +08:00
<head>
<meta charset="UTF-8">
2025-04-18 10:33:51 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
2024-12-12 10:28:03 +08:00
<title>play</title>
</head>
<style>
2025-02-21 15:55:35 +08:00
html {
margin: 0;
padding: 0;
2025-04-18 10:33:51 +08:00
overflow: hidden;
/* 防止滚动条出现 */
}
2025-04-18 10:33:51 +08:00
2025-02-21 15:55:35 +08:00
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: white;
2025-04-18 10:33:51 +08:00
overflow: hidden;
/* 防止滚动条出现 */
2025-02-21 15:55:35 +08:00
display: flex;
align-items: center;
justify-content: center;
}
2025-04-18 10:33:51 +08:00
#player {
2025-04-18 10:33:51 +08:00
object-fit: cover;
2025-04-28 10:59:48 +08:00
width: 100vw;
height: 100vh;
}
</style>
2025-04-18 10:33:51 +08:00
2024-12-12 10:28:03 +08:00
<body>
2025-02-21 15:55:35 +08:00
2025-04-18 10:33:51 +08:00
<video autoplay muted poster="images/loader-thumb.jpg" id="player">
</video>
<script src="jmuxer.min.js"></script>
<script>
2024-12-12 10:28:03 +08:00
2025-04-18 10:33:51 +08:00
if (typeof JMuxer === 'undefined') {
console.error("JMuxer is not defined. Check if jmuxer.min.js is loaded correctly.");
} else {
console.log("JMuxer loaded successfully.");
2024-12-12 10:28:03 +08:00
}
2025-04-18 10:33:51 +08:00
let jmuxer;
window.onload = function () {
try {
jmuxer = new JMuxer({
node: 'player',
mode: 'video',
debug: false,
readfpsfromtrack: true,
flushingTime: 0, // 立即刷新
clearBuffer: true, // 丢弃延迟帧
fps: 25, // 强制指定帧率
onReady: () => {
console.log('播放器初始化完成');
// 通知Flutter端准备就绪
window.Flutter.postMessage('ready');
},
onMissingVideoFrames: (missingFrames) => {
// console.log('Missing video frames:', missingFrames);
},
});
} catch (e) {
console.error("Error initializing JMuxer:", e);
}
};
2025-02-21 15:55:35 +08:00
2025-04-18 10:33:51 +08:00
// Feed data from Flutter
function feedDataFromFlutter(data) {
const buffer = new Uint8Array(data);
jmuxer.feed({
video: buffer,
duration: 40 // 每帧持续时间40ms25fps
});
}
2024-12-12 10:28:03 +08:00
// Optional: notify Flutter
function notifyFlutter(message) {
if (window.Flutter) {
window.Flutter.postMessage(message);
} else {
console.log("Flutter interface not found. Message: " + message);
}
}
2025-02-21 15:55:35 +08:00
2025-04-18 10:33:51 +08:00
// Function to return to Flutter page
function returnToFlutter() {
notifyFlutter("Returning to Flutter page");
}
// 添加清理方法
function cleanupJMuxer() {
if (jmuxer) {
try {
jmuxer.destroy();
jmuxer = null;
console.log('JMuxer cleaned up successfully');
window.Flutter.postMessage('cleanup_complete');
} catch (e) {
console.error('Error cleaning up JMuxer:', e);
window.Flutter.postMessage('cleanup_error');
}
}
}
</script>
2024-12-12 10:28:03 +08:00
</body>
2025-04-18 10:33:51 +08:00
</html>