119 lines
3.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>play</title>
</head>
<style>
html {
margin: 0;
padding: 0;
overflow: hidden;
/* 防止滚动条出现 */
}
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: white;
overflow: hidden;
/* 防止滚动条出现 */
display: flex;
align-items: center;
justify-content: center;
}
#player {
object-fit: cover;
height: 56vh;
transform: rotate(-90deg);
}
</style>
<body>
<video autoplay muted poster="images/loader-thumb.jpg" id="player">
</video>
<script src="jmuxer.min.js"></script>
<script>
if (typeof JMuxer === 'undefined') {
console.error("JMuxer is not defined. Check if jmuxer.min.js is loaded correctly.");
} else {
console.log("JMuxer loaded successfully.");
}
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);
}
};
// Feed data from Flutter
function feedDataFromFlutter(data) {
const buffer = new Uint8Array(data);
jmuxer.feed({
video: buffer,
duration: 40 // 每帧持续时间40ms25fps
});
}
// Optional: notify Flutter
function notifyFlutter(message) {
if (window.Flutter) {
window.Flutter.postMessage(message);
} else {
console.log("Flutter interface not found. Message: " + message);
}
}
// 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>
</body>
</html>