Issue with playing video on Phonegap in Android

19,725 views
Skip to first unread message

Sreylin

unread,
Dec 24, 2010, 1:39:45 AM12/24/10
to phonegap
I am new for developing application with Phonegap in Android. Now I
face a problem, so i am seeking for some helps. The problem is that I
cannot play the video file (.mp4) in Phonegap application in Android
by using <video> tag of HTML5. I believe that some of you may meet
this problem and already solve it. Hope you can share with me. Thank
in advance.

Roger Barr

unread,
Jan 15, 2011, 5:31:15 AM1/15/11
to phonegap
Following up on the problem Sreylin has posted.

We're developing a magazine (an app version of www.lifeofandroid.com)
app using PhoneGap. Great tool btw.

We'd love to put some of the video reviews into the magazine so that
they play in the app (without launching a browser).

I've looked everywhere for advice on how to do this within the
phonegap wiki, google group but haven't found anybody who has done
this yet on android. There are quite a few discussions on video on
iPhone.

Anyone got this working yet and would care to share the advice?

thanks in advance

Roger

James Allsup

unread,
Jan 16, 2011, 7:01:58 AM1/16/11
to phonegap
I'd imagine that mp4 may not be supported in android, but you can
specify multiple video sources in the <video> tag W3Schools have the
best details for this:
http://www.w3schools.com/html5/html5_video.asp

James

Sreylin Doung

unread,
Jan 18, 2011, 1:11:37 AM1/18/11
to James Allsup, phonegap
Thank for your reply, Jame. If I use the video tag in webpage browsed
by Android's browser, it works. The problem is that it doesn't work in
the webview in Phonegap. Anyone has any idea about this?

Bryce Curtis

unread,
Jan 18, 2011, 10:53:05 AM1/18/11
to phonegap
Sreylin,

I believe a fix in commit
https://github.com/phonegap/phonegap-android/commit/a7415bcfc9b103afdaae705612907c0ae13bc00e
will solve your problem. (1/4/11) You can download from github and
give it a try, or wait until 0.9.4 is available.

If you want to post your html video tag snippet, I can try it out to
verify.

Bryce

nb

unread,
Feb 28, 2011, 4:21:24 PM2/28/11
to phonegap
Hi Bryce,

I am unable to get the HTML5 video playing correctly inside the
WebView on my android device. Is there anything that needs to be done
in order to enable the functionality?

Thanks,
NB

On Jan 18, 8:53 am, Bryce Curtis <curtis.br...@gmail.com> wrote:
> Sreylin,
>
> I believe a fix in commithttps://github.com/phonegap/phonegap-android/commit/a7415bcfc9b103afd...

nb

unread,
Feb 28, 2011, 6:53:43 PM2/28/11
to phon...@googlegroups.com
I wasn't able to get HTMl5 video working, but I did find a nice workaround thanks to this link http://www.codelark.com/2010/05/12/android-viewing-video-from-embedded-webview/.

Add this to your onCreate method:

        appView.setDownloadListener(new DownloadListener()

        {

            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long size)

            {

                Intent viewIntent = new Intent(Intent.ACTION_VIEW);

                viewIntent.setDataAndType(Uri.parse(url), mimeType);

                

                try

                {

                    startActivity(viewIntent);

                }

                catch (ActivityNotFoundException ex)

                {

                    Log.w("YourLogTag", "Couldn't find activity to view mimetype: " + mimeType);

                }

            }

        });

In your javascript set the URL of the window to the URL of the video it will begin playing immediately in the full screen media player.


Nick


http://www.becktech.us

Ari

unread,
Mar 7, 2011, 5:03:08 PM3/7/11
to phonegap
Hello,

I am having the same issue as Sreylin (mp4 working in the browser but
not a phonegap app) using Phonegap 0.9.4. When I add the code included
in the last post to onCreate, I can compile the app but it crashes on
launch.

Thank you for any help

duncan deng

unread,
Mar 29, 2011, 5:08:29 AM3/29/11
to phonegap
SOLUTION:

Thanks to nb and Jim Butcher at
http://www.codelark.com/2010/05/12/android-viewing-video-from-embedded-webview/

Step 1: add downloadListener on the appView

in App.java after line 'super.loadUrl("file:///android_asset/www/
index.html");' add the following:

appView.setDownloadListener(new DownloadListener()

{

public void onDownloadStart(String url, String userAgent,
String
contentDisposition, String mimeType, long size)

{

Intent viewIntent = new Intent(Intent.ACTION_VIEW);

viewIntent.setDataAndType(Uri.parse(url), mimeType);

try

{

startActivity(viewIntent);

}

catch (ActivityNotFoundException ex)

{

Log.w("YourLogTag", "Couldn't find activity to
view
mimetype: " + mimeType);

}

}

});

Step 2: Whenever you want to play the video, in javascript set the
current window url with the video url :

eg: "location.href = 'http://video.mp4';" because the current window
url has been changed to a external source, the downloadListerner we
set earlier will be triggered.
And the as the download starts, the native android player will
automatic play the supported mime type file(in this case .mp4)

Ari

unread,
Mar 29, 2011, 12:43:04 PM3/29/11
to phonegap
Working perfectly. Thank you so much

Pierre Emmanuel CHAUT

unread,
Mar 29, 2011, 2:34:51 PM3/29/11
to phon...@googlegroups.com
Is it ? It was not working for me .. It was only working for remote videos, not local ones.
(so I made my own plugin)

Have you tested local videos ?

2011/3/29 Ari <ari....@gmail.com>
Working perfectly.  Thank you so much

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Ari

unread,
Mar 29, 2011, 5:49:33 PM3/29/11
to phonegap
No, I was having trouble with remote videos before I used your fix.
Haven't tested local, sorry

Ari

unread,
Mar 29, 2011, 6:06:29 PM3/29/11
to phonegap
Whoops, I mean Duncan's fix is working for me. I did see your plugin
on another thread and have it handy in case the need for local video
arises

Benoît Pointet

unread,
Mar 31, 2011, 6:34:32 AM3/31/11
to phonegap
the fix works fine here too.
I'm trying to apply what's suggeested in
http://www.codelark.com/2010/05/12/android-viewing-video-from-embedded-webview/

...
you can add a YourActivity.finish() after the
startActivity(viewIntent) call inside the try block.
This skips the blank WebView view when the user is done with the
media player and presses the back key to return to your
application ...

How can I get to know the activity so to finish it?

gino dsa

unread,
Sep 7, 2011, 10:41:51 AM9/7/11
to phon...@googlegroups.com
Yes how to come back from the video directly into the app?

Naren Kondavaty

unread,
Sep 16, 2011, 7:11:24 AM9/16/11
to phon...@googlegroups.com
I am also stuck with this.  Using WebIntent (Phonegap Plugin) Created Intent to Started Activity to MediaPlayer Demo(This is a droid Activity) and passed Url in intent.putExtras .  Able to play the Url video in the media player.  Once the video is played.  In surfaceDestroyed method called finish method.  onDestroy method is getting called, player is getting released, but in the foreground blank window is displayed still.  Have to manually press the back button to go to the app.  Is there any way to close the called Media Player and return to app automatically once the video is completed.  Any help in this is greatly appreciated.

Actually we used jwplayer to play video.  It was working in iPhone, Safari and Android browser, but the same is not working in Android phonegap.  Since it is not working tried the above alternative.  So in Android 2.2 using Web Intent directly opened the Url , where it prompts for Movies/Internet and selecting Movies it plays the video, but in Android 2.3 and above it is opening the Url into the background and the app is getting stuck so instead of calling Url directly via intent, called the Media player.  It is playing video but once played not able to come back to app automatically.






Robert Dupuy

unread,
Sep 30, 2011, 11:14:27 AM9/30/11
to phonegap
Guys I'd just like to say the solution posted above works and it works
for local video as well.

There is a problem that the Video player is not allowed - doesn't have
permission to play the videos but you can play them from the sdcard
instead.

So what I do, is in the java part of my phonegap project right before
super.loadUrl I put

try
{
CopyAssets();
}
catch (Exception e)
{
Log.w("YourLogTag", e.getMessage());
}


and then somewhere on the internet I found a copyassets (sorry don't
remember where).

public void CopyAssets() throws IOException {
AssetManager assetManager = getAssets();
String[] files = null;
File dir;
try {
files = assetManager.list("video");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}

File sdCard = Environment.getExternalStorageDirectory();
dir = new File (sdCard.getAbsolutePath() + "/TheJourney/video");
dir.mkdirs();


for(String filename : files) {
InputStream in = null;
try {
in = assetManager.open("video/" + filename);
File f=new
File(Environment.getExternalStorageDirectory() + "/TheJourney/video",
filename);

BufferedOutputStream bufEcrivain = new
BufferedOutputStream((new FileOutputStream(f)));
BufferedInputStream VideoReader = new
BufferedInputStream(in);
byte[] buff = new byte[32 * 1024];
int len;
while( (len = VideoReader.read(buff)) > 0 ){
bufEcrivain.write(buff,0,len);
}
bufEcrivain.flush();
bufEcrivain.close();


} catch(IOException e) {
Log.e("tag", e.getMessage());
}
}
}


and that is copying videos that I put in a "video" folder that is in
the assets - to a location on the sdcard.

Now on the javascript side, when I call location.href = '/mnt/sdcard/
TheJourney/video/preview.mp4'

well its not hard coded like that, you have to use phonegap's
utilities to determine the location of the sdcard, and then where your
video was copied too.

Eh, its a bit of a space waster, but - I found this strategy worked
for me, anyway.



Vishal Rajpal

unread,
Oct 5, 2011, 6:34:37 AM10/5/11
to phon...@googlegroups.com
I have tried doing tis..works fine for remote files..and for the local files the recent post I was unable to play the video..I got the file path through the phonegap utilities (same as you have mentioned but through phonegap) tried to set the path but the application crashed...Any suggestions

Simon MacDonald

unread,
Oct 5, 2011, 10:26:06 AM10/5/11
to phon...@googlegroups.com
Guys, I did a small plugin to play video's on the weekend. You can see it here:


I'm going to push it up to phonegap-plugins once I have a few spare minutes. Use it and offer suggestions.

Simon Mac Donald
http://hi.im/simonmacdonald


On Wed, Oct 5, 2011 at 6:34 AM, Vishal Rajpal <vishal...@gmail.com> wrote:
I have tried doing tis..works fine for remote files..and for the local files the recent post I was unable to play the video..I got the file path through the phonegap utilities (same as you have mentioned but through phonegap) tried to set the path but the application crashed...Any suggestions

Nanomo

unread,
Oct 5, 2011, 12:54:31 PM10/5/11
to phonegap
great thanks a lot i will be using it in the next app!!!

On Oct 5, 11:26 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Guys, I did a small plugin to play video's on the weekend. You can see it
> here:
>
> https://github.com/macdonst/phonegap-plugins/tree/video/Android/Video...
>
> I'm going to push it up to phonegap-plugins once I have a few spare minutes.
> Use it and offer suggestions.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Robert Dupuy

unread,
Oct 11, 2011, 12:31:23 PM10/11/11
to phonegap
Hey - Simon, thanks for that plugin.

I found that the solution I was using earlier (and posted above)
working for Android 2.3. But when I went to try it on Android 2.2 -
didn't work.

Now I installed your plugin - and it worked for Android 2.2 in the
emulator- and worked on a real phone when using a 3rd party video
player.

However, for me, it crashed if I used the Android built-in Video
player. It kept giving nullpointer when launching
com.wise.video_player

Well I don't sometimes use http and other times use a local file - I
only use a local file.

I know almost nothing about Java, but I changed the plug-in in this
manner:

private void playVideo(String url) {
// Create URI
Uri uri = Uri.parse(url);
// Display video player
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(url);
intent.setDataAndType(Uri.fromFile(file), "video/*");

this.ctx.startActivity(intent);
}

Obviously I've changed it to just read from local files - but for
whatever odd reason, now the default video player on my LG Optimus T -
will not crash, and actuallys plays the videos!
It's cool, thanks for that plugin.

Simon MacDonald

unread,
Oct 11, 2011, 11:07:50 PM10/11/11
to phon...@googlegroups.com
That is some interesting code but if it fixes a bug I can encorporate it. I'll check for "file://" to begin the url parameter and if so I will use the Uri.fromFile() method instead.

What values are you passing in for your url?

rizwan yaqub

unread,
Oct 19, 2011, 4:36:37 AM10/19/11
to phonegap
hi simon thnx alot for the plugin but still i am unable to play video
mp4 files. it just plays audio but not video of the mp4 file.. can u
plx help out..!!!

On Oct 5, 7:26 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Guys, I did a small plugin to play video's on the weekend. You can see it
> here:
>
> https://github.com/macdonst/phonegap-plugins/tree/video/Android/Video...
>
> I'm going to push it up to phonegap-plugins once I have a few spare minutes.
> Use it and offer suggestions.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Simon MacDonald

unread,
Oct 19, 2011, 2:05:12 PM10/19/11
to phon...@googlegroups.com
Can you post up an example .mp4 that I can try out?

Dewang Shah

unread,
Nov 17, 2011, 9:15:19 AM11/17/11
to phonegap
Hi,

The plugin works and I am able to play the video. However, when I stop
the video and hit the Back button on my phone I get taken to the App
Drawer rather than back to the PhoneGap app that I was running when I
started the video.

Is there any way to make it go back to the app?

Thanks,
Dewang

On Oct 12, 3:07 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> That is some interesting code but if it fixes a bug I can encorporate it.
> I'll check for "file://" to begin the url parameter and if so I will use the
> Uri.fromFile() method instead.
>
> What values are you passing in for your url?
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Simon MacDonald

unread,
Nov 17, 2011, 3:13:25 PM11/17/11
to phon...@googlegroups.com
Hmmm...that is odd after pushing the back button you should go back to
the app. The video intent is only laying a view on top of the running
app it doesn't mess around with the back button.

Dewang Shah

unread,
Nov 18, 2011, 4:11:25 AM11/18/11
to phon...@googlegroups.com
Yes, that's what I thought as well. It takes me back to the app if I hit back before the video starts playing. But if I stop the video after it starts and then hit back it just goes to the home screen.

Simon MacDonald

unread,
Nov 18, 2011, 9:44:19 AM11/18/11
to phon...@googlegroups.com
That's really weird and I can't reproduce. What app is started via
intent to do the video playing?

Dewang Shah

unread,
Nov 18, 2011, 9:58:43 AM11/18/11
to phon...@googlegroups.com
I'm running on an HTC phone so it is their media player. The strange thing is that it is intermittent. Some times it goes back to the app but other times it goes to the home screen.

Dewang Shah

unread,
Nov 18, 2011, 10:14:26 AM11/18/11
to phon...@googlegroups.com
OK, just figured out what was causing that. The video plays in landscape mode and somehow the app was not able to handle that so it was closing and I ended up at the home screen. I found this entirely by accident because we had a requirement to have the app locked to portrait mode. So now every time I hit the back button I am taken to the app.

Looks like somehow the app does not like being in landscape mode.

Simon MacDonald

unread,
Nov 18, 2011, 10:16:26 AM11/18/11
to phon...@googlegroups.com
Ah, that'd explain why I couldn't repo.

producerism

unread,
Dec 8, 2011, 1:35:17 PM12/8/11
to phon...@googlegroups.com
thanks for the info and plugin!  Exactly what I needed.

laminina

unread,
Dec 11, 2011, 1:05:29 AM12/11/11
to phon...@googlegroups.com
Hi Everyone,

The solution appies to open the default media player the device has, but is there any solution/help to still play the video inside our webview, I would like to have more than the video in my UI, (lets say ui controls, info, links ...) I would really appreciate if someone has some insights on how to accomplish this,,,,

we need a solid solution thinking that we will have to do custom work for iOS as well....we are not playing only mp4, we will play several formats.

thanks so much!

Priyanka

unread,
Jan 18, 2012, 5:26:26 AM1/18/12
to phon...@googlegroups.com
Hello Simon,
                    I have just started developing apps in phonegap. The VideoPlayer Plugin helped me play the video on Phonegap in Android.
Just wanted to know if it is possible to package the plugin into a jar file so that there would be no need to repeat the steps for every app needing this plugin.

Thank You :)  

Simon MacDonald

unread,
Jan 20, 2012, 11:32:59 AM1/20/12
to phon...@googlegroups.com
It should be pretty easy to compile the .java file and package the
resulting .class into a .jar. I haven't bothered to do it myself but
it shouldn't be any different then jarring up any other Java code.

Priyanka

unread,
Feb 13, 2012, 4:59:45 AM2/13/12
to phonegap
Thanx Simon...
actually I tried it but found many errors "Droidgap package not
found ... "
maybe I have missed out something. Will try again, but in case if u
did it successfully plz do share ur steps.

On Jan 20, 9:32 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> It should be pretty easy to compile the .java file and package the
> resulting .class into a .jar. I haven't bothered to do it myself but
> it shouldn't be any different then jarring up any other Java code.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

shruti kaushik

unread,
Mar 23, 2012, 12:14:41 AM3/23/12
to phon...@googlegroups.com
hey i am new in phonegap..i have tried playing video with this code

<video controls src="http://www.bluegini.com/videos/1low/prog_index.m3u8">
 </video>

but i am not getting the video in my emulator..so i tried with plugin..but i am not getting with that plugin also.please tell me step by step that how to use plugin in android.


On Friday, December 24, 2010 12:09:45 PM UTC+5:30, Sreylin wrote:
I am new for developing application with Phonegap in Android. Now I
face a problem, so i am seeking for some helps. The problem is that I
cannot play the video file (.mp4) in Phonegap application in Android
by using <video> tag of HTML5. I believe that some of you may meet
this problem and already solve it. Hope you can share with me. Thank
in advance.

On Friday, December 24, 2010 12:09:45 PM UTC+5:30, Sreylin wrote:
I am new for developing application with Phonegap in Android. Now I
face a problem, so i am seeking for some helps. The problem is that I
cannot play the video file (.mp4) in Phonegap application in Android
by using <video> tag of HTML5. I believe that some of you may meet
this problem and already solve it. Hope you can share with me. Thank
in advance.

Sandeep Kumar

unread,
Mar 24, 2012, 12:04:33 AM3/24/12
to phon...@googlegroups.com


hi pls check this its working fro me
youtubevideoplay.zip

Simon MacDonald

unread,
Mar 26, 2012, 12:06:30 PM3/26/12
to phon...@googlegroups.com
A .m3u8 is a playlist file and not a video file. The video player is probably choking on the file as it can't determine a program to open it.
--

bagadi bala krishna

unread,
Apr 23, 2012, 2:16:01 PM4/23/12
to phon...@googlegroups.com
Hi all,

I am new to phonegap development in android. I have a requirement to control player size i.e; i want re-size the video player. 

I have tried with the html video tag with height and width attributes . 

I am stuck up with this please any help me.




Thank you advance.

Anthony Gasparich

unread,
May 11, 2012, 8:08:11 AM5/11/12
to phon...@googlegroups.com
I am having this same issue. Has anyone resolved it? 

>> >> > For more options, visit this group at
>> >> >http://groups.google.com/group/phonegap?hl=en?hl=en
>> >>
>> >> > For more info on PhoneGap or to download the code go
>> >> > towww.phonegap.com
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "phonegap" group.
>> > To post to this group, send email to phon...@googlegroups.com
>> > To unsubscribe from this group, send email to

>> > For more options, visit this group at
>> > http://groups.google.com/group/phonegap?hl=en?hl=en
>> >
>> > For more info on PhoneGap or to download the code go to www.phonegap.com
>> >
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "phonegap" group.
>> To post to this group, send email to phon...@googlegroups.com
>> To unsubscribe from this group, send email to

>> For more options, visit this group at
>> http://groups.google.com/group/phonegap?hl=en?hl=en
>>
>> For more info on PhoneGap or to download the code go to www.phonegap.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to

> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

Sujatha Thati

unread,
Jul 31, 2013, 8:25:23 AM7/31/13
to phon...@googlegroups.com
Hi Narendra kumar.
I am very new to Phonegap.
We want an application which is supported for both ios and android.
Is it phonegap technology suitable for need?
My project consists of major tasks like forum,database connnectivity,push notifications,facebook status updation and soon. Is it possible to implemet all these modules in phonegap?


On Friday, September 16, 2011 4:41:24 PM UTC+5:30, నరేంద్ర కుమార్ wrote:
I am also stuck with this.  Using WebIntent (Phonegap Plugin) Created Intent to Started Activity to MediaPlayer Demo(This is a droid Activity) and passed Url in intent.putExtras .  Able to play the Url video in the media player.  Once the video is played.  In surfaceDestroyed method called finish method.  onDestroy method is getting called, player is getting released, but in the foreground blank window is displayed still.  Have to manually press the back button to go to the app.  Is there any way to close the called Media Player and return to app automatically once the video is completed.  Any help in this is greatly appreciated.

Actually we used jwplayer to play video.  It was working in iPhone, Safari and Android browser, but the same is not working in Android phonegap.  Since it is not working tried the above alternative.  So in Android 2.2 using Web Intent directly opened the Url , where it prompts for Movies/Internet and selecting Movies it plays the video, but in Android 2.3 and above it is opening the Url into the background and the app is getting stuck so instead of calling Url directly via intent, called the Media player.  It is playing video but once played not able to come back to app automatically.






William SerGio

unread,
Aug 17, 2013, 10:00:36 AM8/17/13
to phon...@googlegroups.com, roger...@googlemail.com
Hi,

I sell mobile my Apps for Android on national TV and I also distribute MY mobile apps using my own TV Spots and half hour infomercials which allows me to distribute any app to millions of mobile phones within 90 days.

So I have a large user base to get feedback from.

I found that the "quality" of playback is not as important as the "search and selection GUI"... so if you have an Android app that needs to play I would focus on the GUI and search and not quality.
I use Cooliris to play videos in Android and people love the GUI and the search I develop--I have plenty of FREE source code on my website you can check out: www.SwipeClouds.com

Bill SerGio, The Infomercial King



On Saturday, January 15, 2011 5:31:15 AM UTC-5, Roger Barr wrote:
Following up on the problem Sreylin has posted.

We're developing a magazine (an app version of www.lifeofandroid.com)
app using PhoneGap. Great tool btw.

We'd love to put some of the video reviews into the magazine so that
they play in the app (without launching a browser).

I've looked everywhere for advice on how to do this within the
phonegap wiki, google group but haven't found anybody who has done
this yet on android. There are quite a few discussions on video on
iPhone.

Anyone got this working yet and would care to share the advice?

thanks in advance

Roger

Lanze Langill

unread,
Jun 11, 2015, 11:35:11 AM6/11/15
to phon...@googlegroups.com, sujatha....@gmail.com
I am having issues playing Facebook Embedded videos with a Phonegap app. Any help?

Jesse Monroy

unread,
Jun 11, 2015, 1:50:02 PM6/11/15
to phon...@googlegroups.com
this is an old thread. start a new thread. explain your issue better. what platform.? iOS, Android,Windows? what is the problem with the video? when is it happening? at start, while playing?
Reply all
Reply to author
Forward
0 new messages