新增web版视频下载功能
This commit is contained in:
parent
fb2bddcbae
commit
20afeb9fa1
@ -23,5 +23,11 @@ mergeInto(LibraryManager.library, {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
WebGLDownloadVideo: function(ptr,fileName) {
|
||||||
|
var url = UTF8ToString(ptr);
|
||||||
|
var name = UTF8ToString(fileName);
|
||||||
|
DownloadVideoFromUrl(url,name);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -16,6 +16,11 @@ public class WebGLDownLoadFile : MonoSingleton<WebGLDownLoadFile>
|
|||||||
[DllImport("__Internal")]
|
[DllImport("__Internal")]
|
||||||
private static extern void WebGLDownloadWord(byte[] array, int size, string reportjson);
|
private static extern void WebGLDownloadWord(byte[] array, int size, string reportjson);
|
||||||
|
|
||||||
|
[DllImport("__Internal")]
|
||||||
|
private static extern void WebGLDownloadVideo(string url, string fileName = "实验视频.mp4");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载Word 方法
|
/// 下载Word 方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,4 +68,9 @@ public class WebGLDownLoadFile : MonoSingleton<WebGLDownLoadFile>
|
|||||||
WebGLDownloadWord(bytes, bytes.Length, reportjson);
|
WebGLDownloadWord(bytes, bytes.Length, reportjson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DownloadVideo(string url, string fileName = "实验视频.mp4")
|
||||||
|
{
|
||||||
|
WebGLDownloadVideo(url, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,30 +1,30 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en-us">
|
<html lang="en-us">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
<title>虚拟实验 | {{{ PRODUCT_NAME }}}</title>
|
<title>虚拟实验 | {{{ PRODUCT_NAME }}}</title>
|
||||||
<link rel="shortcut icon" href="TemplateData/favicon.ico">
|
<link rel="shortcut icon" href="TemplateData/favicon.ico">
|
||||||
<link rel="stylesheet" href="TemplateData/style.css">
|
<link rel="stylesheet" href="TemplateData/style.css">
|
||||||
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/docxtemplater.js"></script>
|
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/docxtemplater.js"></script>
|
||||||
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/pizzip.js"></script>
|
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/pizzip.js"></script>
|
||||||
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/FileSaver.js"></script>
|
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/FileSaver.js"></script>
|
||||||
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/pizzip-utils.js"></script>
|
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/pizzip-utils.js"></script>
|
||||||
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/imagemodule.js"></script>
|
<script type="text/javascript" src="StreamingAssets/WebGLDownloadWordJS/js/imagemodule.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="unity-container" class="unity-desktop">
|
<div id="unity-container" class="unity-desktop">
|
||||||
<canvas id="unity-canvas" width=1280 height=720></canvas>
|
<canvas id="unity-canvas" width=1280 height=720></canvas>
|
||||||
<div id="unity-loading-bar">
|
<div id="unity-loading-bar">
|
||||||
<div id="unity-progress-bar-empty">
|
<div id="unity-progress-bar-empty">
|
||||||
<div id="unity-progress-bar-full"></div>
|
<div id="unity-progress-bar-full"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="unity-warning"> </div>
|
||||||
|
<div id="unity-footer">
|
||||||
|
<div id="unity-fullscreen-button"></div>
|
||||||
|
<div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div id="unity-warning"> </div>
|
|
||||||
<div id="unity-footer">
|
|
||||||
<div id="unity-fullscreen-button"></div>
|
|
||||||
<div id="unity-build-title">{{{ PRODUCT_NAME }}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var container = document.querySelector("#unity-container");
|
var container = document.querySelector("#unity-container");
|
||||||
@ -356,7 +356,52 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加视频下载功能
|
||||||
|
function HtmlDownloadVideo(bytes, fileName) {
|
||||||
|
// 创建Blob对象,指定视频MIME类型
|
||||||
|
var blob = new Blob([bytes], { type: 'video/mp4' });
|
||||||
|
|
||||||
|
// 创建下载链接
|
||||||
|
var url = window.URL.createObjectURL(blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = fileName;
|
||||||
|
|
||||||
|
// 触发下载
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
|
||||||
|
// 清理资源
|
||||||
|
setTimeout(() => {
|
||||||
|
document.body.removeChild(a);
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果需要从URL加载视频并下载
|
||||||
|
function DownloadVideoFromUrl(videoUrl, fileName) {
|
||||||
|
// 使用fetch API获取视频数据
|
||||||
|
fetch(videoUrl)
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.arrayBuffer();
|
||||||
|
})
|
||||||
|
.then(bytes => {
|
||||||
|
// 调用下载函数
|
||||||
|
HtmlDownloadVideo(bytes, fileName);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('error:', error);
|
||||||
|
unityShowBanner('error: ' + error.message, 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user