I'm piecing together a cheapo app that amongst other things "frames" some of our websites... Pretty simple with the WebViewClient
. until I hit the video.
The video is done as HTML5
elements, and these work fine and dandy on Chrome, iPhones, and now that we fixed the encoding issues it works great on Android
in the native browser.
Now the rub: WebView
doesn't like it. At all. I can click on the poster image, and nothing happens.
Googling, I found this which is close, but seems to be based on a 'link' (as in a href...) instead of a video element. (onDownloadListener does not appear to get invoked on video elements...)
I also see references to overriding onShowCustomView, but that seems to not get called on video elements... nor does shouldOverrideUrlLoading..
I would rather not get into "pull xml from the server, reformat it in the app".. by keeping the story layout on the server, I can control the content a bit better without forcing people to keep updating an app. So if I can convince WebView to handle tags like the native browser, that would be best.
I'm clearly missing something obvious.. but I have no clue what.
After long research, I got this thing working. See the following code:
Test.java
HTML%VIDEO.java
custom_screen.xml
video_loading_progress.xml
colors.xml
Manifest.xml
Expecting rest of things you can understand.
Actually, it seems sufficient to merely attach a stock WebChromeClient to the client view, ala
and you need to have hardware acceleration turned on!
At least, if you don't need to play a full-screen video, there's no need to pull the VideoView out of the WebView and push it into the Activity's view. It will play in the video element's allotted rect.
Any ideas how to intercept the expand video button?
Well, apparently this is just not possible without using a JNI to register a plugin to get the video event. (Personally, I am avoiding JNI's since I really don't want to deal with a mess when Atom-based android tablets come out in the next few months, losing the portability of Java.)
The only real alternative seems to be to create a new web page just for WebView and do video the old-school way with an A HREF link as cited in the Codelark url above.
Icky.
This approach works well very till 2.3 And by adding hardwareaccelerated=true it even works from 3.0 to ICS One problem i am facing currently is upon second launch of media player application is getting crashed because i have not stopped playback and released Media player. As VideoSurfaceView object, which we get in onShowCustomView function from 3.0 OS, are specific to browser and not a VideoView object as in, till 2.3 OS How can i access it and stopPlayback and release resources?
I used html5webview to solve this problem.Download and put it into your project then you can code just like this.
To make the video rotatable, put android:configChanges="orientation" code into your Activity for example (Androidmanifest.xml)
and override the onConfigurationChanged method.
On honeycomb use
hardwareaccelerated=true
andpluginstate.on_demand
seems to work