gpt4 book ai didi

electron - 如何在 Electron 中使用 require()?

转载 作者:行者123 更新时间:2023-12-03 12:23:17 25 4
gpt4 key购买 nike

我第一次使用electronwebchimera。我看到这个 demo ,但我不想在主窗口中打开播放器。我不知道如何使用 Electron ,所以我尝试使用呈现索引页面的服务器,并在单击按钮后播放播放器页面。

客户端从服务器加载索引页面:

//this is for webchimera
if (process.platform == 'win32')
process.env['VLC_PLUGIN_PATH'] = require('path').join(__dirname, 'node_modules/wcjs-prebuilt/bin/plugins');


const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
win.loadURL("http://localhost:8888/")

// Open the DevTools.
win.webContents.openDevTools()

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

索引页面包含一个指向播放器页面的链接,如果单击它,服务器将响应播放器页面。服务器在nodejs中。

服务器在 localhost:8888 中运行并发送此 html 页面:

<html>
<head>
<style>
body,html{ width: 100%; height: 100%; padding: 0px; margin:0px }
#player { width: 100%; height: 100% }
</style>
</head>

<body>
<div id="player"></div>
<script>
var wjs = require("wcjs-player");
var player = new wjs("#player").addPlayer({
autoplay: true,
wcjs: require('wcjs-prebuilt')
});
player.addPlaylist("http://archive.org/download/CartoonClassics/Krazy_Kat_- _Keeping_Up_With_Krazy.mp4");
</script>
</body>
</html>

但是我得到这个错误:找不到模块 wcjs-player

我该如何解决这个问题?

附言:我使用服务器只是因为我在决定使用 Electron 之前为 webapp 编写了它。没必要。我可以删除服务器并仅使用客户端。

最佳答案

这意味着模块 wcjs-player 没有安装。在你的控制台/终端运行 npm install wcjs-player 来安装它,这一定有帮助,而且你可能想看看 this

关于electron - 如何在 Electron 中使用 require()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41274017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com