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");

30 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

Sergi Kolesnik 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.

Unknown 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.

Anonymous 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

Anonymous 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.

Unknown 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

Unknown 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.

Unknown 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.

Unknown 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.

Unknown 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.

Anonymous said...

Great work Simon, Thank you.

I have this issue 'Sorry this video cannot be played'.
my video path is:'file:///android_asset/www/v1.mp4'
and I run your example in this link:https://gist.github.com/macdonst/1507162
and I used your plugin version 2.2.0

Also, can it work with updated cordava like 2.5 or 2.7 ?

Thank you,

Anonymous said...

Simin, It works AFTER I tried sdcard path (play video from sdcard folder).

But now there is some error which i couldn't find on google

logcat:

06-29 11:42:31.253: E/DX-PowerManager(16566): [WidgetUpdataService1x4] get dxhome err:android.content.pm.PackageManager$NameNotFoundException: com.dianxinos.dxhome
06-29 11:42:31.253: E/DX-PowerManager(16566): [WidgetUpdataService1x4] get dxlauncher err:android.content.pm.PackageManager$NameNotFoundException: com.dianxinos.dxlauncher
06-29 11:42:31.253: I/DX-PowerManager(16566): [WidgetUpdataService1x4] update Widget RemoteView : android.widget.RemoteViews@41505360

So, what's your opinion ?

Anonymous said...

Sorry Simon, but i'm trying.

The last error was gone, Without knowing the reason of it.
But the video state is the same.

video controls buttons disappears also no back/home .. buttons of device appear, and a lock image/shape is appearing in the top right of video screen.

Now, I can't do anything on mobile or app till video finish at all. It must be finished then back to my app.

I wish if i can share with you the video screen image.

So, What can I do ?

Simon MacDonald said...

@amt

Install a different video player app, use that one to play the video and see if that changes the behaviour.

Anonymous said...

Dear Simon,

Thank you for reply.
I knew that this lock icon is from mobile device itself, and when you press power button it unlocked and video controls appear.

Thank you very much.

Anonymous said...

Also, I try to contact Phonegap google group, but i can't, my questions doesn't appear and no reply from admins.

I'm new in Phonegap and need some help.

Also, I sent my questions on stackoverflow but no response.

Is there any way to get help ?

Thank you.

Simon MacDonald said...

@amt

First post to the group is moderated. Once they get a chance to look over the poster to make sure they are not spammers your messages should show up.

Anonymous said...

Thank you sir for reply,

I wanted to ask if I can remove display screen of video plugin when i use it to play only sound ?

sorry for disturbance,
Thank you again

Simon MacDonald said...

@amt

Why wouldn't you just use the Media class to play the sound then?

http://docs.phonegap.com/en/3.0.0/cordova_media_media.md.html#Media