我第一次使用电子和 webchimera 。我看到这个demo,但我不想在主窗口中打开播放器。我不知道如何使用电子,所以我尝试使用一个呈现索引页面的服务器,并在点击一下按钮后播放播放器页面。
客户端从服务器加载索引页面:
//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>
但是我得到了这个错误:
cannot find module wcjs-player
我该如何解决这个问题?
PS : 我使用服务器只是因为我在决定使用电子之前为webapp编写了它。没必要。我可以删除服务器并仅使用客户端。
答案 0 :(得分:0)
这意味着未安装 wcjs-player 模块。在您的控制台/终端中运行npm install wcjs-player
进行安装,这必须有所帮助,您也可以查看this