Monday, April 2, 2012

Updates to my PhoneGap Plugins

If you've updated to PhoneGap 1.5.0 which is part of our move to the Apache Cordova name and the next step in becoming an official Apache project you've probably noticed a number of plugins have broken. The biggest problem is that a lot of Plugins used this.ctx as an Android Context. Unfortunately due to some internal code changes this.ctx is no longer a Context. Now you have to call this.ctx.getContext(). So I spent sometime updating the ChildBrowser, FtpClient, TTS and VideoPlayer plugins so they would work smoothly with PhoneGap/Cordova 1.5.0.

Also, thanks to some code submitted by Stephanie Sherriff (ssherriff on GitHub) the VideoPlayer plugin can now play files from your Android assets folder. The syntax is pretty simple as well.
window.plugins.videoPlayer.play("file:///android_asset/www/path/to/my/video.mp4");

21 comments:

Michael Tamony said...

Simon do you know if people have had any success using your Video plugin with PhoneGap Build? I have it working in Cordova 1.5 on HTC Evo, but I want to deploy to other platforms. In reviewing the process I see that ChildBrowser is the only supported plugin.

If it is supported do you know the ?

Thank you.

Simon MacDonald said...

@Michael,

You'll have to request for them to add it:

http://community.phonegap.com/nitobi/products/nitobi_phonegap_build?from_gsfn=true

Serhiy Kolesnyk said...

On the matter of cross-platform compatibility, how do you achieve this if you use platform specific plugins?

On a separate note is there inApp purchase plugin for Android? There's plugin here https://github.com/luoihoc/CallbackBillingPlugin but haven't been updated for 5 months.

Simon MacDonald said...

@Serhiy Kolesnyk

Well, the native side has to be implemented in a different language so there isn't much re-use there but you can use the same JavaScript which is how you make things cross platform. Treat the plugin as a black box with the JavaScript as it's public API.

Michael Tamony said...

Simon,

Do you know how to implement CB openExternal on Windows Phone? I have used the plugin files on GitHub. I had to change some stuff from PhoneGap to Cordova and now I'm at least getting it to build and open with showWebPage.

Simon MacDonald said...

Sorry Michael, I do not. I have not touched Windows Phone development at this point.

Michael Tamony said...

You and 98% of the mobile development world.

It was pretty simple to get it all going, but have gotten stuck with openExternal.

juxiang peng said...

hi Simon ,I use the filetransfer download a mp3(audio) file on ios ,and the callback is successful ,however the downloaded mp3 file can't be played back; do u know why ?
I use the full path directory ; like
/var/mobile/.../documents/xxx.mp3 .
the music file packaged in www is work fine。

thanks

Simon MacDonald said...

@juxiang peng

Actually, I have no idea. I don't work with iOS that much.

InnovativePeople said...

Hi Simon,

VideoPlayer Plugin On Android.If I Press One Button after video Playing then after how I reback to my screen.Please help me..

Example Video play full screen If i touch the screen there Done button i press after goto previous screen

Gabriel Mendez said...

I am very to see the Plugin now can play videos from the assets folder. It is a very great improvement.
Just a question: Is there a way to place the player screen into a "div" or something like that, instead of see the video on fullscreen?

Simon MacDonald said...

@Gabriel Mendez

Sorry, there is no way to embed the video into a div or video tag right now.

Dave Armstrong said...

HI Simon,
I've installed your videoplay plugin as noted but when I test iton my android I get a blank page (no errors)so I wonder if I installed it wrong or used the wrong code.

Do you have a sample page could look at?

Simon MacDonald said...

@Dave Armstrong

You'll need to change the reference to phonegap.js but here is a quick example:

https://dl.dropbox.com/u/887989/video.html

zonaib siddiqui said...

hi Simon , i have used in-app purchase plugin for android , but its show me "item not found", i have provided the key, change salt, provide productID ...
can you tell me any reason ???
thanks

Simon MacDonald said...

@zonaib siddiqui

Sorry, I did not write and have never used that plugin.

Michael Steinbacher said...

Hey Simon,

@first, very nice Plugin :)

But i always get an error, when i try to start a video. Logcat says: Path or file not found...
...and the path is definitly correct and the video is there.
By the way, i developing on android 3.2 and cordova 2.2

Thanks a lot!

Simon MacDonald said...

@Michael Steinbacher

Need more info.

Michael Steinbacher said...

... i try to play a video from the assets (no copy to the sdcard). To do this i have a html video tag with a onclick method. When i add a source tag, my app tries to play it, with the reported error.
But when i remove the source tag, it seems to do nothing.
The play method should executes your plugin.
-> window.plugins.VideoPlayer.play("file:///android_asset/video/3e02.mp4");

...need more Infos?
thanks

Simon MacDonald said...

@Michael Steinbacher

Yeah, the output from "adb logcat" would help. Not sure why you are using the video source tag as that is just going to confuse everything. Either use the video tag or the VideoPlayer plugin. However, the video tag doesn't work super great and does not play videos from the assets folder.

Michael Steinbacher said...

Ok, now it works :D

... i created an a href tag to an empty page, where i call your plugin after device ready.

Thanks for your help anyway.