Installation of the plugin is pretty simple:
1. To install the plugin, move www/video.js to your project's www folder and include a reference to it in your html file after phonegap.{ver}.js.
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="video.js"></script>
2. Create a directory within your project called "src/com/phonegap/plugins/video" and copy "src/com/phonegap/plugins/video/VideoPlayer.java" into it.
3. In your res/xml/plugins.xml file add the following line:
<plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/>
Once installed you will be able to play a video by calling:
window.plugins.videoPlayer.play(url);The url parameter can be one of three types:
1. The file:// protocol to play something native to the device such as:
window.plugins.videoPlayer.play("file:///sdcard/MyMovie.mp4");2. The http:// protocol to play something on the internet such as:
window.plugins.videoPlayer.play("http://path.to.my/file.mp4");3. The http:// protocol pointing to a video on YouTube such as:
window.plugins.videoPlayer.play("http://www.youtube.com/watch?v=E0UV5i5jY50");As long as your url has "youtube.com" and contains the video ID (i.e. the v parameter) the VideoPlayer should be able to start the YouTube app on your phone to play the video without any additional user interaction. However, if the phone does not have the YouTube app you are out of luck. In the future I may add a check for this that will ask the user to install the YouTube app first.
Sadly at this point in time the VideoPlayer does not support playing videos from your android asset directory. That is an enhancement for a later date.
So, there you go a pretty simple and easy to use plugin which can get you unstuck if you really need to play a video in your Android PhoneGap application. Lemme know you feedback.
Hi
ReplyDeleteWe did the 3 step installation process, so the video.js is beside the phonegap-1.2.0.js, the XML file is update with the plugin line, and the folder src/com/phonegap/plugins/video with the java file is beside the Eclipse project (We also test is in the www folder just in case).
Well we always get this error
11-22 21:33:34.009: D/PhoneGapLog(416): TypeError: Result of expression 'window.plugins' [undefined] is not an object.
11-22 21:33:34.009: D/PhoneGapLog(416): undefined: Line 1 : TypeError: Result of expression 'window.plugins' [undefined] is not an object.
11-22 21:33:34.009: E/Web Console(416): TypeError: Result of expression 'window.plugins' [undefined] is not an object. at undefined:1
We tested on Android 2.3.3 and Android 3.2
We develop on a Mac using Eclipse
Any idea why we can't make it works?
@JFFortierQc
ReplyDeleteHmm..it sounds like you are setup correctly. Are you waiting for the "deviceready" event before trying to call window.plugins.videoPlayer.play()?
A sample project would look like:
src\com\test\TestActivity.java
src\com\phonegap\plugins\video\VideoPlayer.java
www\index.html
www\phonegap-1.2.0.js
www\video.js
Hi again Simon
ReplyDeleteI remove the JAR of phonegap, configure de Build Path, add the JAR file again, I did a Project > clean...
Now the error is
11-23 13:19:45.452: D/PhoneGapLog(390): TypeError: 'undefined' is not an object (evaluating 'window.plugins.videoPlayer')
11-23 13:19:45.452: D/PhoneGapLog(390): undefined: Line 1 : TypeError: 'undefined' is not an object (evaluating 'window.plugins.videoPlayer')
11-23 13:19:45.452: E/Web Console(390): TypeError: 'undefined' is not an object (evaluating 'window.plugins.videoPlayer') at undefined:1
Same Kind, but the 'window.plugins' is now 'window.plugins.videoPlayer'.
I can't make it works, but the message change so just want to let you know.
Are you usign phonegap-1.2.0.js or a previous version? Are you on Mac or PC? I'm trying to find little difference between you and I to get closer to the bug.
Hi Simon
ReplyDeleteSorry to butter you again.
I apologize. I said that PhoneGap was loaded, because I did the click manually after a long delay. That's true. But seams like PhoneGap never call the On Ready. The file JS is there and an alert at the end of the file is triggered. It means that the path is ok. But I don't know why but it's like it doesn't want to start.
I search on Google and found this
http://www.philliprhodes.com/content/phonegap-deviceready-not-called-android
I test it, I put an alert there to and I know that the listener is set. But deviceready is never triggered.
I'm more then confuse now. No Idea why.
Have you an idea on what can be the problem?
Hi Simon
ReplyDeleteForget about my bug. I just restart from scratch the test project. Now it works.
I really don't understand where was the problem. I did the same, but now the Phonegap instantiate normally. So your plugin too.
Thanks for your help. Also, your plugin is really perfect. I have to test it a bit more to understand what are the video limitation, but I think this is not about your plugin, but more about Androïd itself. I found information there : http://developer.android.com/guide/appendix/media-formats.html#recommendations
Thank again
@JFFortierQc glad to hear it is working for you.
ReplyDeleteHi Simon
ReplyDeleteI have a problem with a local video, if i try to load a video from internet it works fine.
When I try to load the same file as local video, I get an error message "file not supported"
@Corrado what is the path you are trying to play the file from?
ReplyDeleteTried
ReplyDelete"file:///android_asset/www/video/file.mp4"
&
"file:///assets/www/video/file.mp4"
Then I read: "Sadly at this point in time the VideoPlayer does not support playing videos from your android asset directory"
I am also getting error 'Sorry this video cannot be played' while reading video locally (window.plugins.videoPlayer.play("file:///android_asset/www/VTD04_Centrifugal.mp4");)
ReplyDelete@Sudheer
ReplyDeleteYes, I mentioned that problem right in my post:
Sadly at this point in time the VideoPlayer does not support playing videos from your android asset directory. That is an enhancement for a later date.
Can you play videos using rtmp with this plugin?
ReplyDelete@ccabral
ReplyDeleteI've not tried. Do you have an example?
:]
ReplyDeleteSimon Mac Donald - thx !!
I did all the process of instalation, but now i don´t know where tu put the code.
window.plugins.videoPlayer.play("http://path.to.my/file.mp4");
In my page there is a button linked to a video.html where the video will be launched on full screen, play, stop n give a option to replay or to come back to the button´s page.
for instance:
< li id="XY " >< a href="video.html" target="_self" id="menubt" >< span >goods< /span>< /a >< / li >
goods
Thx for the attention. sorry if its a stupid question, i´m new at java, css, html. i´m studying
I am using your plugin to try and play video via a rtmp streaming server. Here is how I am calling the plugin:
ReplyDeletewindow.plugins.videoPlayer.play("rtmp://myURL);
//window.plugins.videoPlayer.play("http://video-js.zencoder.com/oceans-clip.mp4");
The commented out line works perfectly but now I am trying to replicate that with rtmp and I can not.
Would you have any general suggestions?
@ccabral Hmm...now that I look it problem won't do rtmp. Do you have a URL I can use to test?
ReplyDelete@Juan
ReplyDeleteThe probably isn't much point to you have a second video.html file. The player launches full screen and has the stop/pause/play controls. Then if the users wants to go back to your app they just click the back button.
So replace the href to video.html with a javascript call to window.plugins.videoPlayer.play()
hi Simon! Thx for the attention.
ReplyDeletei don´t know if video.js works with dreamweaver cs5.5. I´m working with the latest phonegap. When i compile the app , the emulator goes ok, but i can´t see my video. On AVD i setup a sdcard , opened with DDMS and put my file on that.
< a href="javascript:window.plugins.videoPlayer.play("file:///sdcard/Marcello.mp4");" >test < /a >
The process of instalation for Dreamweaver the same? Thx anyways. =]
@Juan
ReplyDeleteI have no idea on Dreamweaver as I've never used it. If you aren't getting an error in "adb logcat" then it may just be an emulator issue. Have you tried it on a phone?
http://flowplayer.org/plugins/streaming/rtmp.html
ReplyDeleteFlowplayer has a sample rtmp video to demonstrate their streaming support. You could use that.
rtmp://dk2isqp3f.rtmphost.com/flowplayer
flowplayer.rtmp-3.2.3.swf
Hi again Simon! I´ve tested on my asus pad n nothing seems to work. I move my project to eclipse n run it in debug mode. when i click at the buttons with the herf calling the javascript i got this error on console:
ReplyDeleteUncaught SyntaxError: Unexpected token } at file:///android_asset/www/menu.html:216 or
Uncaught SyntaxError: Unexpected end of input
Sorry about bothering you. You know a place where can i see a html using the video.js? Maybe i´m missing somth with java... Thx anyway .. I'm ashamed. I´m stcuked about one month!!
Hey Simon,
ReplyDeletewhere in my Android project do I put a video thst i´d like to call via your plugin?
I´m able to use your plugin with videos in the web but as i´m not allowed to put local videos in the asset folder where can I put them and how can i call that path?
file:///
cheers, sash
@sash
ReplyDeleteYou'll need to copy the file from the assets directory to the /sdcard when your app first starts up. Possibly over the break I can try and get things playing directly from the assets directory.
@Juan
ReplyDeleteI just posted this gist.
https://gist.github.com/1507162
You'll have to change the path but it should work fine. Also you may have to change to the phonegap version you are using.
@ccabral
ReplyDeleteWe'd have to write some extra code into the VideoPlayer to support it. Check out this StackOverflow answer:
http://stackoverflow.com/questions/6006043/how-to-stream-over-rtmp-on-android
Hi Simon!!! I was make some mistakes with java! With your example now everything is working!!!
ReplyDeleteThe plugin is working fine with the phonegap 1.3! No need to rollback!
Really thx! Helped me a lot! SUPER!
Help! How can i configure the video plugin to hide the video controls or disable the pause, backward, or forward button?
ReplyDelete@Yeong
ReplyDeleteThe way I wrote the plugin it isn't possible as I just use an Intent to play the video.
Hello Simon,
ReplyDeleteI have an error with playing the video
"This video cannot be played". It's a remote mp4 video. I installed the plugin as you stated
@samar
ReplyDeleteWhat url are you using?
Hi, I am vishal
ReplyDeletei want to load video from my local storage /data/data/video.3gp . Please reply ASAP.
@Vishal
ReplyDeleteThe url should be:
file:///data/data/video.3gp
but you may have a problem if you application does not have access to read files from that directory. Most Android apps store files on their internal file system at /data/data/
The video couldn't be played.
ReplyDeleteRemote URL, file .mp4, http.
Works fine with in Chrome, but not with your plugin. What im doing wrong?
This video issues killing me T_T
@Unknown
ReplyDeleteI don't really know as you haven't given me much to go on. What do you see in "adb logcat"? Are you doing this on a device or emulator? etc. etc.
Sorry, Simon. Is runned on emulator, now is playing only sound not video.
ReplyDelete@Unknown
ReplyDeleteI don't really trust the emulator for playing video. You are better off testing this on a device if you have one available.
Hello Again Simon,
ReplyDeleteWell, while running more mp4 files I got some files that kept loading then were buffered but did not actually run.
Here is the logCat debug:
01-19 13:10:06.384: D/DroidGap(332): DroidGap.startActivityForResult(intent,-1)
01-19 13:10:06.384: I/ActivityManager(61): Starting: Intent { act=android.intent.action.VIEW dat=http://66.197.168.70/droidanime/Anime/Clannad/7_1_clannad7.mp4 typ=video/* cmp=com.android.gallery/com.android.camera.MovieView } from pid 332
01-19 13:10:06.464: I/WindowManager(61): Setting rotation to 1, animFlags=1
01-19 13:10:06.474: I/ActivityManager(61): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=17 uiMode=17 seq=5}
01-19 13:10:06.574: I/Ads(332): Received ad url: <"url": "http://googleads.g.doubleclick.net:80/mads/gma?preqs=2&u_sd=1.5&slotname=a14d46113b14470&u_w=160&msid=Objects.Company.DroidAnime&cap=m%2Ca&js=afma-sdk-a-v4.3.1&isu=B3EEABB8EE11C2BE770B684D95219ECB&cipa=0&format=320x50_mb&net=ed&app_name=1.android.Objects.Company.DroidAnime&hl=en&u_h=213&u_audio=4&prl=2945&u_so=p&output=html®ion=mobile_app&u_tz=0&ex=1&client_sdk=1&askip=2&pto=0&jsv=1", "afmaNotifyDt": "null">
01-19 13:10:06.933: I/ActivityManager(61): Displayed com.android.gallery/com.android.camera.MovieView: +550ms (total +831ms)
01-19 13:10:07.033: D/MediaPlayer(361): Couldn't open file on client side, trying server side
01-19 13:10:07.043: I/StagefrightPlayer(34): setDataSource('http://66.197.168.70/droidanime/Anime/Clannad/7_1_clannad7.mp4')
01-19 13:10:07.063: I/NuHTTPDataSource(34): connect to 66.197.168.70:80/droidanime/Anime/Clannad/7_1_clannad7.mp4 @0
01-19 13:10:07.224: W/InputManagerService(61): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@406084f0 (uid=10034 pid=332)
01-19 13:10:07.284: W/IInputConnectionWrapper(332): showStatusIcon on inactive InputConnection
01-19 13:10:09.274: D/dalvikvm(61): GC_EXPLICIT freed 363K, 48% free 4225K/8071K, external 3173K/4373K, paused 77ms
01-19 13:10:10.324: W/webcore(332): Can't get the viewWidth after the first layout
01-19 13:10:11.234: I/Ads(332): onReceiveAd()
01-19 13:10:11.234: W/Ads(332): Not enough space to show ad! Wants: <480, 75>, Has: <240, 282>
01-19 13:10:11.234: D/SoftKeyboardDetect(332): Ignore this event
01-19 13:10:28.904: I/NuCachedSource2(34): new range: offset= 71374979
01-19 13:10:28.904: I/NuHTTPDataSource(34): connect to 66.197.168.70:80/droidanime/Anime/Clannad/7_1_clannad7.mp4 @71374979
01-19 13:10:34.286: I/NuCachedSource2(34): new range: offset= 94946210
01-19 13:10:34.286: I/NuHTTPDataSource(34): connect to 66.197.168.70:80/droidanime/Anime/Clannad/7_1_clannad7.mp4 @94946210
01-19 13:10:47.684: D/dalvikvm(332): GC_CONCURRENT freed 1188K, 56% free 3103K/6983K, external 2379K/2971K, paused 4ms+5ms
01-19 13:10:47.724: D/webviewglue(332): nativeDestroy view: 0x60dce0
01-19 13:10:47.734: D/webviewglue(332): nativeDestroy view: 0x566c40
01-19 13:11:09.224: I/NuCachedSource2(34): ERROR_END_OF_STREAM
01-19 13:11:10.324: D/MediaPlayer(361): getMetadata
01-19 13:11:10.354: I/NuCachedSource2(34): new range: offset= 71374987
01-19 13:11:10.440: I/NuHTTPDataSource(34): connect to 66.197.168.70:80/droidanime/Anime/Clannad/7_1_clannad7.mp4 @71374987
01-19 13:11:13.803: D/AudioSink(34): bufferCount (4) is too small and increased to 12
01-19 13:11:13.803: I/AwesomePlayer(34): cache is running low (0.51 secs) , pausing.
Thanks Simon
Hey Simon,
ReplyDeleteVideo Plugin works great. Now that I have videos playing full screen, I was wondering if you would know how to get the videos to play on a portion of the screen, i.e. a defined box. Is this possible with your plugin or the native player?
I have done some reading on Android VideoView but haven't been able to get that to work with phone gap.
If you had any insight on how to play video inside phone gap in only a portion of the screen that would be great.
Thanks.
@ccabral
ReplyDeleteWell that is what the video tag is supposed to be for but as we know it is broken in WebView right now. However, there is light at the end of the tunnel. We are working on an update to PhoneGap for late February which will allow you to embedded PhoneGap into your Android app. This way you can have two (or more) views in the same activity 1 is the PhoneGap view and the other is whatever you want and in your case a VideoView. So, in summary we can't do it right now but the capabilities are coming.
Simon,
ReplyDeleteThank you for response and I appreciate you help. Sorry for the sake of redundancy here, but at this time there is no way to write a plugin or something similar within Phone Gap to play a video not in full screen. Sorry to ask again but I need a definitive no.
Thanks again.
@ccabral
ReplyDeleteIt is possible but not trivial. You would need to modify the source of the PhoneGap framework in order to do it though. Yay open source.
What I am saying is that it'll be much easier once 1.5 is released at the end of February.
@samar
ReplyDeleteSorry for not seeing your comment earlier. I actually have no idea why you can't play that mp4 perhaps it is an encoding error.
Hello. I have written an app for kids and I need to open a youtube video in a way that doees not allow kids to access other potetial harmful content on youtube (now they can put the phone in portrait mode and search or see related videos that may not be for kids...).
ReplyDeleteI would appreciate any sollution, maybe a parameter send to youtube, a builtin player that could play the youtube videos as well or a webview embedded video?
Thank you very much. :)
@Dragos
ReplyDeleteSorry, I don't know how to do what you want. For the VideoPlayer plugin I only fire off the intent to start the YouTube app. I'm not sure if there is anyway you can prevent people from going to other videos once it is started.
How do I add a button, for example, to the top left corner that overlays on top of any playing video? This would be a "back" button and takes me back to the app from the video.
ReplyDeleteThanks
@alzika
ReplyDeleteIt is best just to use the back button provided by Android. The way I wrote the plugin it just starts an intent so you get whatever that intent provides. If you really want a back button you may need to write your own Java code to setup the correct View with a back button.
Hi Simon,
ReplyDeleteI noticed that there is a new version of Phone Gap, 1.4.1. Is this the release you were referring to that will support multiple views?
Thanks.
@ccabral
ReplyDeleteNo, not 1.4.1. 1.5 will have some support for embedding PhoneGap as a component in your Android app.
How do I include the video plugin in with the PhoneGap build service where I upload a zip file?
ReplyDeleteI'm confused since I don't know where the java file for this would go.
I'm trying desperately to get an app launched for a client who came up to me last minute needing video capabilities cross-platform. Sometimes they truly don't understand what all is involved, especially since I'm a PHP coder and not an app developer.
Thanks
@alzika
ReplyDeleteI don't have anything to do with the PhoenGap Build Service. You are better off asking your question at:
http://community.phonegap.com/nitobi/products/nitobi_phonegap_build?from_gsfn=true
Hello Simon,
ReplyDeleteI have setup the code as above.
when I play video, the screen was open and got error like "error this video cannot be played"
I tried below code.
window.plugins.VideoPlayer.play("http://videos-cdn.mozilla.net/brand/Mozilla_Firefox_Manifesto_v0.2_640.mp4");
please help..
thanks..
Hi,
ReplyDeletei'm italian so i'm sorry for my english. First of all i wanna say that your plugin is wonderfull and provides the only important thing that phonegap doesn't have: video support on android.
I've notice a problem in some device. Using my HTC Desire if i play video and then press back button it's return in the page where i click button (that call playvideo method).. but in some device, like xperia x10 and galaxy tab, if i press the back button it's back in the home of the application and restart it. I can notice that it's restart because i load the second page by ajax, and in that device it's reload the page as it was just start the app. Do you know why it appens?
Thank's a lot
@MB
ReplyDeleteSorry, I'm not sure why the app is restarting when you return to it. Perhaps you get low on memory while the video is playing so Android clears out your app so when you return to it on the stack it has to be restarted.
The other thing you want to check is that you have the following attribute in your AndroidManifest.xml file:
android:configChanges="orientation|keyboardHidden|screenSize"
Hi Simon
ReplyDeleteyour plugin is working fine for me, I even succeeded in copying the videos on-the-fly on app start to the system's 'data'-directory to play them locally with the plugin.
Unfortunately my android app - which was derived from an ipad app I made before also using phonegap where there was no problem embedding the videos in the web view - always opens the videos fullscreen using the system's video player.
You mentioned that with phonegap 1.5 (I upgraded to it today) it would be possible to embed videos in web view rather then firing them up in the videoplayer. Is there already an example available?
Best regards
Frank
Hi Simon
ReplyDeletemany thanks for the video plugin, I was able to include it in my android project, I even succeeded in copying my app's video files on app start to the system's 'data' directory to play them locally. My app is derived from an iPad app where it's no problem to embed videos in the web view, but which wasn't possible until now with phonegap for android. You mentioned that there would be a solution with phonegap 1.5.0 for finally embedding videos, is there already an example available?
Best regards
Frank
Hello.
ReplyDeleteHow can we embed now a video in page with the 1.5 version on Android?
Hope it is possible now, as I understood from you.
Thank you. :)
@Dragos
ReplyDeletePhoneGap does not support Android 1.5 as the number of phones with that particular release are few and far between. Also, if you try to use a HTML5 video tag on that version of Android you will find that it is broken. Sorry I can't be of more help.
Hello.
ReplyDeleteI was reffering to phonegap v 1.5.
Is it possible to embed video in html now on android 2.3 using latest version of phonegap?
Thank you. :)
@Dragos
ReplyDeleteYou'll still need to use my plugin on Android 2.3. They haven't fixed the video tag yet.
@OurFrank
ReplyDeleteSorry for the confusion but later versions of PhoneGap won't be able to fix the video embed bug in the WebView. However, PhoneGap is moving to a component based approach so you will be able to create an Android application that contains multiple views where one could be a PhoneGap View and another could be a video player view.
Hey,
ReplyDeleteI want to play a group of videos one after each other. So if one video ends it automatically starts the next, but if the user exits early using the backbutton, then it stops playing anymore.
I've been playing about with the callbacks (looking at the barcode plugin for user cancelling), but am struggling quite a bit. Anyone have any code or pointers to help with this?
I have used your video plugin.no error is coming but in emulator they are showing force close.and one more question where should i put
ReplyDeletewindow.plugins.videoPlayer.play("http://www.youtube.com/watch?v=E0UV5i5jY50");
this code in android..
please help me
@Shruti
ReplyDeleteNot sure why you are getting a force close. Some more info on that would help me debug it. The window.plugins.videoPlayer.play() code is JavaScript and you need to put that in your HTML. It could be part of a href or be called when you click a button. It's up to you.
@THem
ReplyDeleteHmmmm...the way the video player code is structured you wouldn't be able to get that information. I'm doing a startActivity not a startActivityForResult which is what we'd need to do in order to detect a cancel. I think you've emailed me as well so I will send you some pointers and maybe you can contribute the code back to the repo.
Hi Simon.
ReplyDeleteThanks for the plugin. Are there any changes to the setup for someone running Codova 1.5 as opposed to PhoneGap?
Also, what are the chances of getting the player to play within a div?
Thanks Kindly,
John
@Unknown i.e. John
ReplyDeleteNo, the plugin should work fine with 1.5.0 as I made sure to add in legacy stubs to support old plugins in the Cordova code.
No, there is not chance of getting the VideoPlayer to be in a div. We've got a lot of work to do on Cordova to enable it to be a component that can be embedded multiple times.
I just wanted to make mention that I have submitted a pull request in GitHub that is a rough solution for playing video from the assets folder.
ReplyDeleteBasically, it copies the video to internal storage before playing it.
It isn't thoroughly tested, only with my own application, but hopefully it will help some people. Also, if others can test it themselves, that would be good.
https://github.com/phonegap/phonegap-plugins/pull/423
Cheers,
Steph
@Steph
ReplyDeleteThanks for the pull request. I'll look it over more later.
@Steph
ReplyDeleteI applied your pull request and updated the code to work with 1.5.0. I want to do a blog post on the update can you contact me via email so I can give you some credit.
@Bhumika
ReplyDeleteI get the same error for that URL. Possibly it is an unsupported codec.
Hi Simon,
ReplyDeleteThanks for the great plugin. :)
However, I have a requirement that a Background audio can be played or paused with the video, also the video be inset in a layout and the layout needs to have a header and a footer with some content.
So is there any way to achieve this.
Regards,
Manish
Also, can you please guide me as to how can that activity be launched as "ActivityWithResult" ??
ReplyDeleteRegards,
Manish
Hi,
ReplyDeleteThis works like a charm, but if someone have more than one video players installed a popup window comes up first ti choose a player. How can we skip this and play the video into android video player by default?
Where is the source code?
ReplyDelete@bikash
ReplyDeleteIt is the first link in the post.
https://github.com/phonegap/phonegap-plugins/tree/master/Android/VideoPlayer
@Shahid Saeed
ReplyDeleteWell, that is an Android bit of functionality so I don't want to mess with it too much. Basically, if more than one app registers for the "android.intent.action.VIEW" intent with mime type "video/*" you'll see this behaviour.
If you start specifying the exact class to start with your intent it will cause you problems as you move from device to device as not all manufacturers use the same video player code. That is Samsung video player is not equal to the HTC video player.
You are better off telling your user to pick a default video player.
@Manish
ReplyDeleteWell, you'd need to start the background audio before you launch the video player as it loads another intent to play the video. You'd have no control of the video once it starts playing.
Honestly, your requirements sound like you should be writing a native component/plugin that you can call to play your video as what you need to go is above and beyond what my plugin can handle.
@Simon
ReplyDeleteI am on that path, that the page which will show the video with the other buttons and UI, will be a native activity, which will be launched by the PG app on page X. At the end of the video player activity, it will finish, which should automatically bring it to the PG app and on page X.
But in case, the video player page is interrupted, the app should ideally be launched so that I directs to page X.
(Does this happen by default?)
Or do I have to write code for that?
(If I have to, what I have planned is that the Video Playing activity will send some data in the bundle extras and the MainActivity of the PG app will launch index.html or X.html, based on the value in the bundle extra!)
Does that seem sound or is there any basic fault in my thinking?
Thanks for the help,
Manish
I am getting error in Videoplayer.java file :
ReplyDeleteFile fp = new File(this.ctx.getContext().getFilesDir() + "/" + filename);
Error msg:
The method getContext() is undefined for the type PhonegapActivity
Iam using eclipse Indigo in windows XP
@tESTER
ReplyDeleteIf you are using PhoneGap 1.4.1 or lower change "ctx.getContext()" to "ctx".
Hello Simon,
ReplyDeleteThanks for the awesome plugin.
I am creating an Android App and using Cordova-1.5.0 along with video plugin.
I have a question to ask, the video plays perfectly fine but as soon as the video play is completed it gets me out of the application rather than going back to the previous page.
Any idea what to do for preventing it to exit from the application?
Regards,
Aqeeb
@qeeb
ReplyDeleteIt sounds like the OS is clearing out your application to save on memory. When we use Intents on Android we are essentially starting a new program and putting the current one in the on hold state. If the OS needs memory it can kill on hold programs. How much memory does you phone have?
Hi,
ReplyDeleteThe RAM size 256, and the App is still in the memory as it can be seen in DDMS.
Regards,
Aqeeb
Hello Simon,
ReplyDeleteI am still facing the same problem.
The control gets me out of the application as soon as the video is completed.
The RAM size 256 and phonegap version is Cordova-1.5.0
Have a look at the LogCat.
05-02 14:00:55.886: I/ActivityManager(72): Starting: Intent { act=android.intent.action.VIEW dat=file:///sdcard/video/v.mp4 typ=video/* cmp=com.android.gallery/com.android.camera.MovieView } from pid 5758
05-02 14:00:55.926: I/WindowManager(72): Setting rotation to 1, animFlags=1
05-02 14:00:55.966: I/ActivityManager(72): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=11}
05-02 14:00:56.266: I/ActivityManager(72): Displayed com.android.gallery/com.android.camera.MovieView: +344ms
05-02 14:00:56.616: I/StagefrightPlayer(34): setDataSource('/sdcard/video/v.mp4')
05-02 14:00:57.576: D/MediaPlayer(1051): getMetadata
05-02 14:00:57.576: D/AudioSink(34): bufferCount (4) is too small and increased to 12
05-02 14:00:58.196: W/InputManagerService(72): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@40652dc0 (uid=10034 pid=5758)
05-02 14:00:58.216: W/IInputConnectionWrapper(5758): showStatusIcon on inactive InputConnection
05-02 14:00:58.436: W/AudioFlinger(34): write blocked for 107 msecs, 115 delayed writes, thread 0xc658
05-02 14:00:59.266: D/dalvikvm(72): GC_EXPLICIT freed 103K, 52% free 4259K/8711K, external 3125K/3903K, paused 240ms
05-02 14:01:00.796: W/InputManagerService(72): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406d73e8
05-02 14:01:03.126: E/MemoryHeapBase(34): error opening /dev/pmem_adsp: No such file or directory
05-02 14:01:03.126: I/SoftwareRenderer(34): Creating physical memory heap failed, reverting to regular heap.
05-02 14:01:03.916: W/AudioFlinger(34): write blocked for 105 msecs, 142 delayed writes, thread 0xc658
05-02 14:01:08.998: W/AudioFlinger(34): write blocked for 71 msecs, 171 delayed writes, thread 0xc658
05-02 14:01:14.446: W/AudioFlinger(34): write blocked for 99 msecs, 199 delayed writes, thread 0xc658
05-02 14:01:19.499: W/AudioFlinger(34): write blocked for 82 msecs, 228 delayed writes, thread 0xc658
05-02 14:01:24.590: W/AudioFlinger(34): write blocked for 82 msecs, 256 delayed writes, thread 0xc658
05-02 14:01:28.046: D/DroidGap(5758): Origin to allow: http://127.0.0.1*
05-02 14:01:28.046: I/CordovaLog(5758): Found log level DEBUG
05-02 14:01:28.046: I/CordovaLog(5758): Changing log level to DEBUG(3)
05-02 14:01:28.046: D/DroidGap(5758): DroidGap.onCreate()
05-02 14:01:28.087: D/DroidGap(5758): DroidGap.loadUrl(file:///android_asset/www/MockUpGymVideoPage.html)
05-02 14:01:28.087: D/DroidGap(5758): DroidGap: url=file:///android_asset/www/MockUpGymVideoPage.html baseUrl=file:///android_asset/www/
05-02 14:01:28.096: D/DroidGap(5758): DroidGap.init()
05-02 14:01:28.277: D/dalvikvm(5758): GC_EXTERNAL_ALLOC freed 801K, 54% free 2948K/6407K, external 2032K/2137K, paused 129ms
05-02 14:01:28.446: I/Database(5758): sqlite returned: error code = 14, msg = cannot open file at source line 25467
05-02 14:01:28.456: I/Database(5758): sqlite returned: error code = 14, msg = cannot open file at source line 25467
05-02 14:01:28.546: D/SoftKeyboardDetect(5758): Ignore this event
05-02 14:01:28.676: I/WindowManager(72): Setting rotation to 0, animFlags=1
05-02 14:01:28.746: I/ActivityManager(72): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=12}
05-02 14:01:29.006: D/SoftKeyboardDetect(5758): Ignore this event
05-02 14:01:29.966: W/IInputConnectionWrapper(1051): showStatusIcon on inactive InputConnection
Any idea how to get through this problem.
Regards,
Aqeeb
thanks
ReplyDeleteI am novice in all of this, but I really need to make it work, but id doesnt work for me (my version of phoneGap is cordova 1.6.1). Could anybody attach the whole phoneGap project folder and *.apk file, please? Thank you and sorry for my bad english
ReplyDeleteHi Simon ,
ReplyDeleteHope you doing well.
i am just exploring phonegap as much as possible.
this is very interesting tutorial thanks a ton for this.
I have a doubt that is working fine when i am accessing it from browser from my galaxy tab device.
But when i tried to use the samae in the phonegap app,either it is crashes up my app or just play the sound some times.
what would be the reason.. ?
in short i want to use in HTML page it self in a Phonegap application and dont want to pass control to other external application so taht video gets played on current page itself.is it possible in any way?
Thanks and Regards ,
Vaibhav Parikh
@Vaibhav
ReplyDeleteWell the video tag is broken in Android and my plugin seems to be the only way to get around the issue. Sorry to say.
Is there a way to add a poster to this script?
ReplyDelete@Tony
ReplyDeleteBy poster I guess you mean an image in the app? You could just display a image and give it a click/tap handler to call the video player.
Hi,
ReplyDeleteThanks for the videoplayer.
I wanted to use the same way for audio playing. And it's work well by doing some change.
private static final String MP3 = ".mp3";
...
// Display video or audio player
intent = new Intent(Intent.ACTION_VIEW);
if (url.contains(MP3)) {
intent.setDataAndType(uri, "audio/*");
} else {
intent.setDataAndType(uri, "video/*");
}
} else {
// Display video or audio player
intent = new Intent(Intent.ACTION_VIEW);
if (url.contains(MP3)) {
intent.setDataAndType(uri, "audio/*");
} else {
intent.setDataAndType(uri, "video/*");
}
}
bye
Bes
Works like a charm! Thanks!!
ReplyDeleteHi Simon
ReplyDeleteI integerate video player plugin in my phonegap application successfully,
Now i want to change video screen orientation and reduce the height and width of the video player .
Is it posssible?
The code you have provided regarding Video plugin is good. But in this it is saving video into internal storage.What i want is i want to play video directly without saving into any internal or external storage. I tried but getting error in simulator as This video cannot be played. Can you help me with this. Waiting for your reply..
ReplyDeleteThanks in advance...
@Raghu
ReplyDeleteWhat URL do you pass to the VideoPlayer?
@luckeelaxmi
ReplyDeleteI just fire off the video player intent in order to handle the video. On my Samsung phone the video player only plays in landscape mode so I have no idea how to force it into portrait or if it is even possible.
//in button onclick="show()" method i am passing the particular url....
ReplyDeletefunction show()
{
window.plugins.videoPlayer.play("file:///android_asset/www/BigBuckBunny.mp4");
}
@Raghu
ReplyDeleteYeah, if you embed the video in your assets folder the VideoPlayer application cannot read the video. In order to play it, it must first be copied to the SD card. Sorry, there is no way around it.
If we are passing one web url(not from assets folder) directly, then will there be any chance... like the following code..
ReplyDelete//in button onclick="show()"
function show()
{
window.plugins.videoPlayer.play("http://s509.photobucket.com/albums/s338/eveanthony/?action=view¤t=Video013.mp4 ");
}
@Raghu
ReplyDeleteYeah, that should just stream from the web.
i followed the following code.
ReplyDeletewindow.plugins.videoPlayer.play("http://www.youtube.com/watch?v=IBTE-RoMsvw&feature=player_embedded#t=6s ");
i gave directly web url, but when i clicks the button it was not responding. Its not navigating page.. May i know whats the problem is...
@Raghu
ReplyDeleteMake sure you have the YouTube app installed or you won't be able to play the video.
Is there any way to play a vimeo video from this plugin?
ReplyDelete@wildrhombus
ReplyDeleteNo, not currently. However, if you knew the intent to start along with a unique ID to reference the vimeo video it probably wouldn't be too hard to add.
I'm a bit new to android, but I don't mind playing with the code. How do I figure out the intent?
ReplyDelete@wildrhombus
ReplyDeleteI'd google around or search the vimeo site. I'm sure I can add this functionality in fairly quickly but I don't have the time to do the research right now.
I've been doing that, and the best I can come up with is using the browser to go to the vimeo page. I can't figure out what url and what intent I need to actually play the video without going to the browser first.
ReplyDeleteIf I figure it out, I'll let you know.
@Simon MacDonald
ReplyDeleteThank you for the plugin and all the support you give around it.
I did read on the link below that your videoplayer was able to play file from the android_assert, is that true?
https://github.com/phonegap/phonegap-plugins/tree/938fd9d04981e2e8c138c07df41ee4f401cf5cb2/Android/VideoPlayer/src/com/phonegap/plugins/video
@yvon colin
ReplyDeleteYes, the plugin was updated to support the playing of files from the android assets directory. See this post:
http://simonmacdonald.blogspot.com/2012/04/updates-to-my-phonegap-plugins.html
Hey Simon,
ReplyDeletenice plugin - solves the first problem i had in my app..
I'm wondering if it is possible to play a video inline like the webkit-playsinline command is doing it in the video-tag..
any idea? or just not possible?
Ben
I confirm that with this update the plugin works well for file located in android_assert even with phonegap/cordova1.8. Nice work Simon congrats!
ReplyDelete@Ben
ReplyDeleteRight now it is not possible. The video tag is broken in the WebView. We are working on making it possible to have multiple views (web,native) in the same PhoneGap application which will allow us to solve this problem but that is coming in PG 2.0 in July. Not sure if we'll be able to play in line video until Google fixes this bug:
https://code.google.com/p/android/issues/detail?id=22254
As always thank you for your tiered-less afford and support..
ReplyDeleteI have been spending weeks getting Videos to really work and thanks to this plugin and some heavy googling I got something that work, but I am not super happy with all the conditions on the different OS and even OS versions i have to make things work..
If you need someone to test the PhoneGap 2.0 Video interface I will be happy to try it out.. i currently are doing Android and iPhone but will be looking at Windows Phone shortly.
Thanks again
Kim
Hi Simon
ReplyDeleteFirst of all, I'm sorry about my english because I'm Vietnamese. I have a trouble with your video plugin. I test my Phonegap app on Android 2.3.3 and Android 4.0.3 but I can only hear audio, can't see video when I play remote video, with local video is error 'Sorry this video cannot be played', although I copied video to sdcard. Do you know why it happens? Thanks!
@Dung Do
ReplyDeleteThe video codec is probably not supported by Android. Check out:
http://developer.android.com/guide/appendix/media-formats.html
Hi Simon,
ReplyDeleteI have created application using cordova 1.8.1.
I tried to play mp4 video but app gives error as
'Sorry this video cannot be played'.
So, I copied the video files on sdcard and successfully played in default player.
Why does not the videos played in my app?
Thanks!
@Suhas
ReplyDeleteWhat url are you trying to play when the mp4 from?
Hi Simon, thanks for continuing to answer questions on this. I am trying to play stream a video that has a changing address based on an attribute. Phonegap 1.8.0. I am using the following code:
ReplyDeletefunction playVideoLink(){
var videoCode = videoLinks[exerciseName];
url = "'http://m.sworkit.com/assets" + videoCode + "'";
window.plugins.videoPlayer.play(url);
}
I get the 'Sorry this video cannot be played'.
The link that should play is exerciseName = /Video/Pushup.mp4
So in the end, 'http://m.sworkit.com/assets/Video/Pushup.mp4'
I can get alert to show url equals this, but is there just no way to use a variable instead of a full http link? I can get this to play:
window.plugins.videoPlayer.play('http://m.sworkit.com/assets/Video/Pushup.mp4');
thanks a lot,
ReplyDeleteworking fine!
Thank you so much for this contribution... unfortunately, everytime I try to call window.plugins.videoPlayer.play, it falls into an infinite loop of re-initializing the DroidGap and eventually crashes with a StackOverflowError exception... Have you run into that before? Here is the gist of my error log. https://gist.github.com/3041384
ReplyDelete@Travis
ReplyDeleteThis is a bug in 1.9.0 that I've already checked in a fix for. Not sure when the next release will be dropped. For the mean time you can either revert to 1.8.1 or build the latest out of the source repo.
Drop the release for 1.9.0! ;)
ReplyDeleteThe link for "Android PhoneGap" in the text "Using this plugin requires Android PhoneGap" at https://github.com/phonegap/phonegap-plugins/tree/master/Android/VideoPlayer results in 404 error.
ReplyDelete@Bonozo
ReplyDeleteSorry if you are looking for a plugin update to 1.9.0 it will be coming soon. I'm working on some stuff for PhoneGap Android core so that the plugins don't need to be updated as it is such a pain.
Also, I can't find the broken link you referred to.
(A) To find the broken link:
ReplyDelete1> On this blog page, in the first paragraph, there is a "VideoPlayer" link to https://github.com/phonegap/phonegap-plugins/tree/master/Android/VideoPlayer
2> There, is a section called "Adding the Plugin to your project"
3> In this section, there is a link to "Android PhoneGap".
4> This link (https://github.com/phonegap/phonegap-android) results in 404 error
***
(B) On the same "VideoPlayer" github page as (A) above, in the "Using the plugin" section, it reads: "The plugin creates the object window.plugins.video".
Q: Is it "window.plugins.video" or "window.plugins.videoPlayer" or both?
***
(C) In the same "VideoPlayer" github page under "Adding the Plugin to your project" [as per (A) above], it reads: 'Create a directory within your project called "src/com/phonegap/plugins/video" and move VideoPlayer.java into it.'
Q: Should it be renamed to Cordova for Cordova builds?
***
Thank you very much Simon, we look forward to your 1.9.0 release!
@Bonozo
ReplyDeleteAh, I gotcha. I made the doc fixes for A and B. As for C, no keep it in com.phongap.plugins as the VideoPlayer.java package declaration is com.phongap.plugins. Thanks for pointing out the broken links.
Hi! Simon:
ReplyDeleteThis plugin is amazing, i tried in Android 4.0.3 and works, but I tried in Android 2.3.3 and 2.3.6 and error is:Uncaught TypeError: Cannot read property 'videoPlayer' of undefined at file:///android_asset/www/index.html:75, the call to the video.js is after the phonegap, I'm usign phonegap 1.8.1, Can you Help me?... Thanks
@Unknown
ReplyDeleteThe VideoPlayer plugin will work fine on Android 2.x. It looks like the video.js is not getting executed properly. Possibly you are not getting the "deviceready" event from PhoneGap. Do other PG API calls work?
but that the deviceready?, my project is executed in delegate and event Bind but not deviceready.... the syntaxis is:
ReplyDeletesrc="cordova-1.8.1.js
src="video.js"
Thanks
@Unknown
ReplyDeleteYou have to make sure you get the "device ready" event or the Plugin won't be registered properly.
please help me :( I'm using the network navigator plugin and notification and not work the error is 07-10 17:38:57.741: D/CordovaLog(32511): file:///android_asset/www/index.html: Line 1 : Uncaught TypeError: Cannot call method 'play' of undefined
ReplyDeletethanks
@Unknown
ReplyDeleteIt doesn't look like you've loaded the video.js file properly. Plus, how could you being calling play in line one of your html?
Hi Simon!
ReplyDeleteThank you for this awsome plugin!
It works great on my Samsung Galaxy SII. But I can't make it work on my Acer tablet Iconia Tab!
The link of my video is: / sdcard/Android/data/my.app/videos/video.mp4
The same link is used on my Galaxy and it work fine...
When I try to play the video, the Eclipse's logCat print : DroidGap.startActivityForResult(intent,-1)
Any idea? Thank you in advance for your help!
@Valentin
ReplyDeleteAre you sure that is the correct path on the Acer?
hi simon,
ReplyDeleteyour code working is fine,but i want to set poster tag for video element as related playing video first frame image then only user understand what video play my self....please give suggetion to me
@Simon
ReplyDeleteThanks for your quick response!
I found the solution! On the Iconia Tab, the link to the video must contain file://! So I just add
uri = Uri.parse("file://" + uri); before the Intent instantiation (on the last "else" of the playVideo method) and it solve the issue! This change does not disturb the reading on my Samsung.
But on the tablet, I have to play the video with the Google vido player. If I try with the Acer one, the file is not found!
Thanks again for your job and contribution!
@gk
ReplyDeleteYou should see my other sub project Corinthian where I monkey punch the video element and replace it with a call to the VideoPlayer plugin. Check it out and see if it can help you as it is in pre-alpha stage right now and needs more eyes.
http://macdonst.github.com/corinthian/
07-20 16:06:02.628: E/Web Console(1784): Uncaught TypeError: Cannot read property 'videoPlayer' of undefined at file:///android_asset/www/index1.html:4
ReplyDeletewhereas index1.html is the file where i want to call the video>>
and index is the home page>>
@Tahir
ReplyDeleteYou need to load cordova.js and video.js on each page that you want to use the Plugin not just on the main page.
@InnovativePeople
ReplyDeleteYeah, there is nothing I can do about the full screen issue. When the video is done playing click the back button and you will go back to your app.
@RyanSpartan
ReplyDeleteFirst, sorry for not responding sooner. Your comment got flagged as spam. I think the root cause of your issue is the singe quotes in your url variable. You should get rid of those.
App freezes after video play
ReplyDeleteI'm running the Android SDK (revision 20) and Eclipse (Juno) on Ubuntu 12.4. I test on a Galaxy Tab. I downloaded and built the latest Cordova (cordova-2.0.0.jar). I have the VideoPlayer PhoneGap plugin working with errors (details below. It worked well on my Galaxy Tab. But I needed to add cookie support since my application uses cookies to authenticate users. After enabling cookies, the app seemed to work fine (and cookies are enabled); however, the app freezes after playing videos. If I call window.reload() in the JS code, the app is OK, but the app completely loses context since it restarts. Thinking the problem might be the cookies, I switched from cookies to local storage, which worked, too; however, the app still freezes after video play. Turning off cookies and/or local storage eliminates the freezing problem, but like I mentioned, my app needs cookies.
When I run the app from Eclipse, LogCat reports an "Uncaught ReferenceError: PhoneGap is not defined" (in video.js). The following JS line generates the above error:
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("videoPlayer", new VideoPlayer());
I'm including the Cordova JS file in index.html before video.js, but I still had problems with the above line and I could not invoke the videoPlayer plug-in. So, instead of invoking the video player with "window.plugins.videoPlayer.play(URL);", I used "VideoPlayer.prototype.play(URL);" That worked! I could start my app as a Android app, browse to my videos and play them. But, when I enabled cookies, the app started freezing after exiting the video player. As I mentioned, using local storage instead of cookies didn't help (app still froze). Also, I am getting a "singleCursorHandlerTouchEvent -getEditableSupport FASLE" in Eclipse LogCat every time I click on something, but I get that anyway (before and after the freeze, even with cookie support off).
Any ideas? Thanks in advance for your help.
I fixed my "PhoneGap is undefined" error by dropping back to PhoneGap 1.8. So, I can now use "window.plugins.videoPlayer.play(playURL)" from my Javascript to launch the video player; however, my app is still frozen when I return to it (i.e., exit playing the video). Like I said in my last post, that problem goes away when I don't include cookie support.
ReplyDeleteOne other strange behavior is that I have to tap the return button on my Galaxy tab twice to exit my app after playing a video. Before playing a video I can exit the app with only one tap.
User @JimmyBo figured out what was going wrong with his app on this thread:
ReplyDeletehttps://groups.google.com/d/msg/phonegap/jEZVpXUGhI0/uah3OpulsYwJ
I really appreciate this information and will try all the things you put out to try. And you are SO correct about the forums information.
ReplyDeleteHi Simon,
ReplyDeleteIs this plugin working on phonegap 2.0 ?
@anoop
ReplyDeleteYes, it has been updated as explained here:
http://simonmacdonald.blogspot.ca/2012/07/updates-to-plugins-for-phonegap-200.html
Thanx for your replay,
ReplyDeleteis it working on emulator?
i tried it on emulator, didn't get any error but the video is not displayed. I followed the steps that u mention, me using phonegap 2.0.0 and jdk 1.6.
Is there any way to play local (res/raw/*.mp4 or assets/www/*.mp4) videos using VideoView widget?
ReplyDeleteWhat I'm trying to do is to play videos (not fullscreen) inside my Phonegap based app with "onComplete" callback and without controls (play/stop etc.). So redirect to internal media player is not an option.
Is there any way to accomplish this?
@Jaka Certanc
ReplyDeleteAs of 2.0.0 you can now embed a CordovaWebView into a larger Android application. Theoretically it should allow you to play video's inline.
http://docs.phonegap.com/en/2.0.0/guide_cordova-webview_android.md.html#Embedding%20Cordova%20WebView%20on%20Android
@anoop mg
ReplyDeleteYes, most video's work in the emulator.
Hi Simon, Your plugin works great for me.. but currently the plugin opens the video in a player outside the app. Any way to embed the video inside my app? ie Left pane of my app have a list of videos and right side it should play ( right pane of app). Is that possible through phonegap?
ReplyDelete@Prasad Krishna
ReplyDeleteAs of 1.9.0 you can start embedding PhoneGap in a bigger Android app. I'd use PhoneGap for the left pane and a VideoView for the right pane. You can see instructions on how to embed a CordovaWebView in your app at:
http://docs.phonegap.com/en/2.0.0/guide_cordova-webview_index.md.html#Embedding%20WebView
Simon, you really,really made my day! Thanks a lot for this great plugin!!
ReplyDeletehello...from where should i writen that line of playing video. (window.plugins.videoPlayer.play())
ReplyDeleteand wat should i write in HTml file.
could you plz suggest
@khushi aggarwal
ReplyDeleteYou'll need to change the reference to phonegap.js but here is a quick example:
https://dl.dropbox.com/u/887989/video.html
@jvfrance
ReplyDeleteNo but I did accidentally over-write it earlier today. Should be fixed now.
hi simon, can you tell me the code to verify if youtube app is installed or not. Thanls
ReplyDeletehi simon, i want to make sure that users have youtube app installed on android. in iPhone, we can't delete the app. How can i alert users in android?
ReplyDeleteThanks,
Vishal
@Vishal
ReplyDeleteWell that is not something I can give you 100% of an answer on and that's the reason why it isn't in the VideoPlayer plugin. Different devices will have different package names for YouTube. The answer at the following link should most most of the time:
http://stackoverflow.com/a/9375105/41679
sir,
ReplyDeleteWhy don't you attach a sample code on video playing?
@jhansi
ReplyDeleteI did. In the comments you'll see it is at:
https://dl.dropbox.com/u/887989/video.html
Hello simon,
ReplyDeleteI am very new to this phonegap, can u send the .zip for this video Project in phonegap android app...
i am realy not getting it...
@jhansi
ReplyDeleteSorry, I don't have time to put together a full project right now.
@Vishal
ReplyDeleteYou can follow this example to check for an Intent:
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
but the problem is the Intent package name for YouTube changes from version to version and manufacturer to manufacturer.
Hi,
ReplyDeleteI have tried to display the video in the android using the phonegap, i have followed the steps you have mentioned and i do have the latest phonegap-1.2.0.js and video.js used in my application, but i have been getting the issue like " TypeError: Result of expression 'window.plugins.videoPlayer' [undefined] is not an object." Can i have any solution for it.
Thanks in advance
@jagadesh
ReplyDeleteIt doesn't sound like you have included the video.js file correctly. Check out my example file:
https://dl.dropbox.com/u/887989/video.html
thank you very much it is working for me now
ReplyDeleteHi, thanks for your plugin, very nice work. He solves the problem more than perfectly. Opening native player and closing it at end of the video.
ReplyDeleteThanks a lot man!!!
It works perfectly, but is there any way of passing extra parameters to the play Intent (for example, to play it landscaped or these sort of things)
ReplyDeleteThanks.
@Jairo
ReplyDeleteYou'd have to modify the plugin source which you are free to do.
Thanks a lot Simon. It helped me a lot. Saved good amount of time for me.
ReplyDeleteJust wanted to commend you for your work on this plugin. I just published an application that would not have been possible without your plugin. https://play.google.com/store/apps/details?id=com.truli.Truli
ReplyDeleteThank you!
Travis
@Travis
ReplyDeleteThat's great to hear! Congrats on getting your app published.
Some behind the scenes news, the VideoPlayer plugin may not be needed for very much longer. I'm working on it :)
"Some behind the scenes news, the VideoPlayer plugin may not be needed for very much longer. I'm working on it :)"
ReplyDeleteJust when I was going to join the thousands thanking you! I am sure the new "iPlugin 5" will be even more deserving!
Meanwhile, any thoughts on how one could download a video (FileTransfer) but so that its only visible/accessible to the parent app - in Android? (Android does this naturally for native apps).
Thanks for your work Simon, on this and more.
PVS
@Gazer
ReplyDeleteYeah, just don't save it on the /sdcard as that is public to all apps. If you want it only accessible by your app put it in /data/data/{package name} but make sure your internal storage is big enough to handle the video file.
Hello:
ReplyDeleteI return with a follow-up q.
For compatibility across Android and iOS, would you recommend:
window.plugins.videoPlayer.play(fileEntry.fullPath);
If you other blog on FileTransfer you remove the file:/// prefix only for Android, I was wondering if that applies to videoPlayer as well.
Thanks!
PVS
@Gazer
ReplyDeleteI don't even think that iOS has a VideoPlayer plugin.
Correct..
ReplyDeleteI use the videoPlugin for Android and standard video html tag for iOS
Of course, no plugin on iOS! That must have been my duh moment :-)
ReplyDeleteHi Simon,
ReplyDeleteReally great plugin.
In my app I`m trying to implement video player for playing m3u8 files.
Plugin works OK for android ver. 4, but for earlier versions it returns message "This video cannot be played" or similar.
Is it possible to implement some plugin like vitamio or similar to support http streaming for versions 2+?
Does anyone know how I get smoother playback of a video using the VideoPlayer plugin?
ReplyDeleteIt works fine on small/short vids, but when I try playing a 100MB, full screen video, the audio and video is really choppy.
I'm developing for Galaxy Tab 10.1 P7500 (Android 3.1).
Thanks!
...I am playing the video from my assets folder.
ReplyDelete@Velibor Mrdak
ReplyDeleteStreaming isn't very well supported until later versions of Android which is why you see it working in 4+ but not in earlier versions of the OS.
Hi Simon,
ReplyDeleteThanks for the plugin it really helps me a lot, but I'M facing some problem with jelly belly(Android 4.1.1).
My Problem is how does the user gets back to the App screen after the video ends the playing? Rigth now you are lost with a black screen in the standard player and have search and to start the App again.
But with Android 4.0.x (means with ICS) its playing well means after the video ends the playing it get back to the last app screen.
Any idea why its happen with android 4.1.1 .......... Well I'M using Cordova 2.2.0
@Simon:
ReplyDelete"Some behind the scenes news, the VideoPlayer plugin may not be needed for very much longer. I'm working on it :)"
Really exciding.. Can you tell a little more on this?
I hope that your are referring to the "Monkey patching" ..
I really like your plug-in, but will like to use PhoneGapBuild but they are not good at supporting plug-in's so adding Video support to PhoneGap would really help me.
In any case THANKS for the great work
Kim
@Kim Rasmussen
ReplyDeleteWe should be able to patch the web view to support the video tag in Android 2.x/3.x. It will still play full screen but you won't need to add a plugin to get it to work. In Android 4.x you just need to add harwareAccelerated=true to get the video tag to work.
I'm stuck working on camera stuff right now but hope to get back to video soon.
@Simon, is there any way, the video would play in the actual size, rather than the fullscreen?
ReplyDeleteTo follow up on my previous post, the reason for the playback problem was to do with the video itself as the problems occured when you played the video directly in the video player.
ReplyDeleteI solved the problem by downloading and installing "Next Video Converter" to convert the video into a mobile-friendly format (Mobile MP4).
Works a treat now!
@Unknown
ReplyDeleteThe size is controlled by the external video player.
@Sumit Madan
ReplyDeleteYou should only need to hit the back button to return to your app.
instead of giving the blah blah ... steps, can you please just post your code, it will be more helpful
ReplyDelete@shirish herwade
ReplyDeleteI'll tell you the same thing I tell my 8 year old daughter. You'll get a lot farther in life if you are polite when asking someone for help.
+1
ReplyDeleteif you want the video player to callback a function in the java, this is missing in the latest version of the Cordova library.
ReplyDeleteChange this line from :
this.cordova.getActivity().startActivity(intent);
to :
this.cordova.startActivityForResult((Plugin) this, intent, 1);
as well as add the method to override the onActivityResult as per the below:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// your code to handle whatever callback you wish to send. perhaps a callback to return the plugin result.
}
@Abed Jabak
ReplyDeleteI don't think the VideoPlayer ever had that functionality but thanks for the suggestion.
Hi
ReplyDeleteI made an app using phone gap video player plugin and it works gr8..
but when i put it in my other app which runs in android webview ..in webview when i click on video link it gives this exception.
Uncaught TypeError: Object # Object has no method 'exec' at file:///data/data/com.bricolsoftconsulting.demo/webviewfix/www/video.js:21
this is line 21
VideoPlayer.prototype.play = function(url) {
cordova.exec(null, null, "VideoPlayer", "playVideo", [url]);
};
This Load VideoPlayer
@Sudhendu
ReplyDeleteIt doesn't look like Cordova is loaded. Did you include the cordova.js file in your html page?
This comment has been removed by the author.
ReplyDeleteHi Simon,
ReplyDeleteat first thanks for you plugin, it works very well on my android device.
One question, is there any output if the video is ended?
In HTML5 I use the following
Thanks in advance.
Best regards,
Daniel