Wiki

Clone wiki

java-cef / 启用V49对FlashPlayer的支持

一个这世界

这个世界从没有真正的对错和永恒的敌人,Google一直叫嚷着用Html5取代Flash,但却和Adobe合作开发ppflash并内置于chromium(很多代码都是写死了)

在开始这篇文章之前,先把示例代码中默认打开的网页从google换到baidu。

类tests.detailed.MainFrame中219行处,大家自己改一下,我就不上图了。


* 关于chromium的switchvalue

chromium很多运行时配置可以通过命令行传参的方式进行设值,就跟我们使用shutdown /s /t 0进行关机差不多。

在cef里使用SwitchAndValue进行对应,switch是参数名,value是值,当然也有只有switch的,这种一般是明确表示了未某个参数设值。例如上文中的Windows关机命令/s和/t是switch,0是对/t的value。

除了显示地使用命令行传递参数(即java tests.detailed.MainFrame ???)之外,我们可以在代码中对commandline进行晚绑定,这样虽然丧失了一定灵活性,但较为稳定。

实现方法为重载org.cef.handler.CefAppHandlerAdapter.onBeforeCommandLineProcessing函数,拿到commandline进行操作。

* 启用FlashPlayer

cef没有内置flash,毕竟flash还算是第三方软件。

1. 获取ppflash文件

flash插件需要从adobe下载,地址为https://get2.adobe.com/cn/flashplayer/otherversions/

选择PPAPI。应该没有操作系统和x86_64位数限制,因为它是在线安装包。

getflashplayer.png

安装完成后在C:\Windows\System32\Macromed\Flash可以找到文件。

flashplace.png

注意,操作系统位数必须匹配,由于flash是在线安装,它是匹配操作系统位数的,所以64位操作就装的是64位flash,你的java-cef必须是64位

2. 启用flash方式一

在onBeforeCommandLineProcessing函数中使用以下代码进行flash启用,这种方式只能是操作系统安装了flash并且位数匹配

#!java

  @Override
  public void onBeforeCommandLineProcessing(String process_type, CefCommandLine command_line) {
    super.onBeforeCommandLineProcessing(process_type, command_line);
    // 方式一
    command_line.appendSwitch("--enable-system-flash");
  }

保存,编译,启动,打开一个带有flash的网页即可看到效果,例如web.kugou.com

3. 启用flash方式二

如果不敢保证客户机器上安装了flash,且为了flash版本可控性,可以把flash打包进来,使用另外一种方式加载到程序中。

#!java

  @Override
  public void onBeforeCommandLineProcessing(String process_type, CefCommandLine command_line) {
    super.onBeforeCommandLineProcessing(process_type, command_line);
    // 方式一
    //command_line.appendSwitch("--enable-system-flash");
    // 方式二
    command_line.appendSwitchWithValue("ppapi-flash-path", "C:\\java-cef-workspace\\java-cef\\third_party\\flashplayer\\pepflashplayer64_23_0_0_162.dll");
    command_line.appendSwitchWithValue("ppapi-flash-version", "23.0.0.162");
  }

上文中,我预先已经把pepflashplayer64_23_0_0_162.dll和manifest.json两个文件放到java-cef / third-party / flashplayer文件夹下了,这个dll路径似乎只能用绝对路径,我写死了,大家可以通过java代码来取,我就不举例了。

version的值呢在manifest.json中是version的值。

使用方式二的话就可以把flash做成离线包打进我们程序了。

附上我提取的ppapi文件win32 win64

另外,flash的版本不应太低(使用方式二时),因为我估计chromium内部维护了一个flash的版本,低于这个版本时可能会有提示,默认被禁止加载,当然,这只是猜测,并未有代码片段支撑这个猜想。

Updated