Hybrid Plugin Example
From WebOS101
aroldo from the webOS Developer Forum has provided a simple example of a Hybrid sound player plugin, useful for playing sounds with low latency in otherwise web-type applications, where the HTML Audio tag often has a significant lag time on startup. Not only does this serve as a solution for those needing to play sounds with low latency, it also serves as an excellent example of how to construct and compile a Hybrid plugin and use it in an Enyo application.
This uses the C++ code from the phonegap-plugins module available at [phonegap-plugins github].
You can build the plugin in Linux using the included shell scripts, or in Windows using aroldo's port of it. You will need to have both the webOS SDK and PDK environments installed, as well as the CodeSourcery toolchain for cross compiling to webOS.
Windows Build Script
//-------- BUILDIT_PLUGIN --------------------------------
@echo off
@rem Set the device you want to build for to 1
@rem Use Pixi to allow running on either device
set PRE=1
set PIXI=0
set EMULATOR=0
set DEBUG=0
@rem List your source files here
set SRC=SoundPlug.cpp
@rem List the libraries needed
set LIBS=-lSDL -lGLESv2 -lpdl
@rem Name your output executable
set OUTFILE=soundplug_plugin
echo %PRE%
if x%1==xpre (
set PRE=1
) else if x%1==xpixi (
set PIXI=1
) else if x%1==xemulator (
set EMULATOR=1
) else set PIXI=1
if %PRE% equ 0 if %PIXI% equ 0 if %EMULATOR% equ 0 goto :END
if %DEBUG% equ 1 (
set DEVICEOPTS=-g
) else (
set DEVICEOPTS=
)
set CC=arm-none-linux-gnueabi-gcc
set LIBPATH="-L%PALMPDK%\device\lib"
if %EMULATOR% equ 1 (
set CC=i686-pc-linux-gnu-gcc
set LIBPATH="-L %PALMPDK%\emulator\lib"
)
if %PRE% equ 1 (
set DEVICEOPTS=%DEVICEOPTS% -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp
)
if %PIXI% equ 1 (
set DEVICEOPTS=%DEVICEOPTS% -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp
)
echo %DEVICEOPTS%
%CC% %DEVICEOPTS% "-I%PALMPDK%\include\SDL" "-I%PALMPDK%\include" %LIBPATH% -Wl,--allow-shlib-undefined %LIBS% -lSDL -lSDL_mixer -lpdl -s -o %OUTFILE% C:\PalmWebOS\EnyoProjects\<YOUR APP FOLDER>\plugin\%SRC%
goto :EOF
:END
echo Please select the target device by editing the PRE/PIXI variable in this file.
exit /b 1
Packaging Script
//------- PACKAGE_PLUGIN.CMD --------------------------
@rem package_plugin.cmd
call windows\buildit_plugin.cmd
echo filemode.755=SoundPlug > package.properties
palm-package <YOUR APP FOLDER>
Enyo Usage Code
{ kind: enyo.Hybrid, name: "plugin", width: 0, height: 0, params:["0","1"],
executable: "soundplug_plugin", onPluginReady: "handlePluginReady" },
handlePluginReady: function(inSender) {
console.log("plugin initalized");
this.pluginReady = true;
},
play_b: function(){
console.log("play brick");
var status = this.$.plugin.callPluginMethod("play","sound/brick.wav");
},