問題描述
我有一個用于藝術展覽的視頻裝置,其中包含大型視頻(數(shù) GB)和一個在線托管的 web 應用程序.
I have a video installation for an art exhibition with big videos (several GBs) and a online hosted webapp.
由于我想在展覽期間節(jié)省一些帶寬,我想將視頻打包到一個電子應用程序中,在啟動時加載一次網(wǎng)頁,然后從本地文件系統(tǒng)/打包的電子應用程序加載視頻.強>
Since I want to save some bandwith during the exhibition, I would like to package the videos into an electron app, load the webpage once during startup and load the videos from the local filesystem / packaged electron app.
我已經(jīng)實現(xiàn)禁用webSecurity(沒關系,我旁邊沒有人運行這個應用程序)并且我已經(jīng)在JS控制臺中收到錯誤消息
I've already achieved to disable the webSecurity (it's fine, no one beside me runs this application) and I already get the error message in the JS console
GET file:///idle.mp4 net::ERR_FILE_NOT_FOUND
.
我找不到引用本地文件的正確路徑/文件夾,您有什么提示嗎?我不能使用固定/絕對文件路徑,因為在線服務器不知道本地文件路徑..
I cannot find the right path/folder to reference the local file, do you have a hint for me? I can't use a fixed/absolute filepath, since the onlineserver has no knowledge about the local filepath..
我嘗試將視頻文件放入主文件夾和渲染器文件夾,但沒有成功,只顯示上面的錯誤消息.謝謝!
I tried to put the video files into the main and renderer folders, but it doesn't work out and only shows the error message above. Thank you!
目前我在我的 webapp 中引用這樣的視頻:
Currently I'm referencing the videos like this in my webapp:
<video id="id12">
<source src="file:///ship.mp4" type="video/mp4"></source>
</video>
我的文件夾結構如下所示:
My folder structure looks like following:
推薦答案
我自己找到了解決方案,我只需要在我的電子應用程序中創(chuàng)建一個 fileProtocol 攔截器:
I found the solution by myself, I just had to create a fileProtocol interceptor in my electron app:
function createMainWindow() {
protocol.interceptFileProtocol('file', function(req, callback) {
var url = req.url.substr(7);
callback({path: path.normalize(__dirname + url)})
},function (error) {
if (error)
console.error('Failed to register protocol')
})
...
這篇關于Electron 加載遠程 URL 并加載本地文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!