2016-12-22 50 views
2

我第一次使用电子webchimera。我看到这个demo,但我不想在主窗口中打开播放器。我不知道使用电子的好处,所以我尝试使用呈现索引页的服务器,并在点击按钮之后播放页面。从服务器索引页如何在电子中使用require()?

客户端负载:

//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中。在本地主机

Server运行: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: 我只使用一台服务器,因为我在决定使用电子之前为它写了一个web应用程序。没有必要。我可以删除服务器并只使用客户端。

回答

0

这意味着模块未安装wcjs-player。在您的控制台/终端中运行npm install wcjs-player以进行安装,这必须有所帮助,另外,您可能要看看this

相关问题