新增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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -356,6 +356,51 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加视频下载功能
|
||||||
|
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>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user