Skip to content

Node 使用 VLC 播放音视频开发文档 - 3

把 vlc 输出到指定的窗口上

1. 下载 electron 快速入门例子

electron 快速入门项目 https://github.com/electron/electron-quick-start

2. 安装模块

bash
cd electron-quick-start
npm install

3. 修改 main.js,用来获取句柄 id

js
function createWindow() {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

  // and load the index.html of the app.
  mainWindow.loadFile("index.html");

  const hwndBuffer1 = mainWindow.getNativeWindowHandle();
  console.log("hwndBuffer1.readInt32LE()", hwndBuffer1.readInt32LE());
  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

4. 运行例子项目

bash
npm start

5. 你会得到 2360018 一串数字,它是 Windows 的句柄

bash
PS C:\Users\Administrator\Downloads\electron-quick-start-main> npm start

> electron-quick-start@1.0.0 start
> electron .


hwndBuffer1.readInt32LE() 2360018

6. 修改你的 vlcAddon.playMedia 输入第 3 个参数

js
vlcAddon.playMedia(newURL, 5000, 2360018); // 5000ms caching

setTimeout(() => {
  vlcAddon.pauseOrResume();
  console.log("调用暂停");

  setTimeout(() => {
    console.log("调用继续");
    vlcAddon.pauseOrResume();
  }, 5000);
}, 5000);

重新运行项目,记得 修改了 addon.cc 代码要 重新构建

bash
npm run rebuild

你会发现 已经把输出渲染到我们的 electron 窗口了