当前位置: 首页 > 科技观察

Electron使用PepperFlash插件

时间:2023-03-12 17:23:12 科技观察

Electron支持使用PepperFlash插件。要在Electron中使用PepperFlash插件,我们需要手动设置PepperFlash路径并在应用程序中启用PepperFlash。保留一份Flash插件在macOS和Linux上,我们可以在Chrome浏览器的chrome://plugins页面找到PepperFlash插件信息。插件的路径和版本将帮助Election支持它。您也可以将插件复制到另一个路径以保留副本。在Electron中添加插件开关,我们可以直接在命令行中使用--ppapi-flash-path和ppapi-flash-version或者在app的准备事件之前调用app.commandLine.appendSwitch方法。同时添加浏览器窗口插件开关。例如:const{app,BrowserWindow}=require('electron')constpath=require('path')//指定flash路径,假设和main.js放在同一个目录下。letpluginNameswitch(process.platform){case'win32':pluginName='pepflashplayer.dll'breakcase'darwin':pluginName='PepperFlashPlayer.plugin'breakcase'linux':pluginName='libpepflashplayer.so'break}app.commandLine.appendSwitch('ppapi-flash-path',path.join(__dirname,pluginName))//可选:指定flash版本,例如v17.0.0.169app.commandLine.appendSwitch('ppapi-flash-version','17.0.0.169')app.on('ready',()=>{letwin=newBrowserWindow({width:800,height:600,webPreferences:{plugins:true}})win.loadURL(`file://${__dirname}/index.html`)//...})或尝试加载系统安装的PepperFlash插件而不是运输插件,其路径可以通过调用app.getPath('pepperFlashSystemPlugin')获取。要使用webview标签启用插件,请在标签中添加plugins属性。例如,如下所示:故障排除我们可以通过在console是否加载。PepperFlash插件的操作系统必须与Electron的相匹配。在Windows上,一个常见的错误是将32位版本的Flash插件用于64位版本的Electron。在Windows上,传递给--ppapi-flash-path的路径必须使用``作为路径分隔符,使用POSIX风格的路径将不起作用。对于某些操作,例如使用RTMP进行流式传输,需要对播放器的.swf文件授予更多权限。实现此目的的一种方法是使用nw-flash-trust。