├── .gitignore ├── AndroidManifest.xml ├── README.md ├── WebviewVideo.iml ├── ant.properties ├── build.xml ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-ldpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── layout │ ├── main.xml │ └── video_progress.xml └── values │ └── strings.xml └── src └── com └── example └── webview └── MyActivity.java /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WebviewVideo 2 | ============ 3 | 4 | sample app for displaying Html5Video using Webview in Android -------------------------------------------------------------------------------- /WebviewVideo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhgupta/WebviewVideo/39f1277d547d2d8d09fb9e9eab6472b858d140f9/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhgupta/WebviewVideo/39f1277d547d2d8d09fb9e9eab6472b858d140f9/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhgupta/WebviewVideo/39f1277d547d2d8d09fb9e9eab6472b858d140f9/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akhgupta/WebviewVideo/39f1277d547d2d8d09fb9e9eab6472b858d140f9/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 19 | -------------------------------------------------------------------------------- /res/layout/video_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | webview 4 | 5 | -------------------------------------------------------------------------------- /src/com/example/webview/MyActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.webview; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.os.Bundle; 6 | import android.view.KeyEvent; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.webkit.WebChromeClient; 10 | import android.webkit.WebView; 11 | import android.webkit.WebViewClient; 12 | import android.widget.FrameLayout; 13 | 14 | public class MyActivity extends Activity { 15 | private WebView webView; 16 | private FrameLayout customViewContainer; 17 | private WebChromeClient.CustomViewCallback customViewCallback; 18 | private View mCustomView; 19 | private myWebChromeClient mWebChromeClient; 20 | private myWebViewClient mWebViewClient; 21 | 22 | /** 23 | * Called when the activity is first created. 24 | */ 25 | @Override 26 | public void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.main); 29 | customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer); 30 | webView = (WebView) findViewById(R.id.webView); 31 | 32 | mWebViewClient = new myWebViewClient(); 33 | webView.setWebViewClient(mWebViewClient); 34 | 35 | mWebChromeClient = new myWebChromeClient(); 36 | webView.setWebChromeClient(mWebChromeClient); 37 | webView.getSettings().setJavaScriptEnabled(true); 38 | webView.getSettings().setAppCacheEnabled(true); 39 | webView.getSettings().setBuiltInZoomControls(true); 40 | webView.getSettings().setSaveFormData(true); 41 | webView.loadUrl("http://m.youtube.com"); 42 | } 43 | 44 | public boolean inCustomView() { 45 | return (mCustomView != null); 46 | } 47 | 48 | public void hideCustomView() { 49 | mWebChromeClient.onHideCustomView(); 50 | } 51 | 52 | @Override 53 | protected void onPause() { 54 | super.onPause(); //To change body of overridden methods use File | Settings | File Templates. 55 | webView.onPause(); 56 | } 57 | 58 | @Override 59 | protected void onResume() { 60 | super.onResume(); //To change body of overridden methods use File | Settings | File Templates. 61 | webView.onResume(); 62 | } 63 | 64 | @Override 65 | protected void onStop() { 66 | super.onStop(); //To change body of overridden methods use File | Settings | File Templates. 67 | if (inCustomView()) { 68 | hideCustomView(); 69 | } 70 | } 71 | 72 | @Override 73 | public boolean onKeyDown(int keyCode, KeyEvent event) { 74 | if (keyCode == KeyEvent.KEYCODE_BACK) { 75 | 76 | if (inCustomView()) { 77 | hideCustomView(); 78 | return true; 79 | } 80 | 81 | if ((mCustomView == null) && webView.canGoBack()) { 82 | webView.goBack(); 83 | return true; 84 | } 85 | } 86 | return super.onKeyDown(keyCode, event); 87 | } 88 | 89 | class myWebChromeClient extends WebChromeClient { 90 | private Bitmap mDefaultVideoPoster; 91 | private View mVideoProgressView; 92 | 93 | @Override 94 | public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) { 95 | onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates. 96 | } 97 | 98 | @Override 99 | public void onShowCustomView(View view,CustomViewCallback callback) { 100 | 101 | // if a view already exists then immediately terminate the new one 102 | if (mCustomView != null) { 103 | callback.onCustomViewHidden(); 104 | return; 105 | } 106 | mCustomView = view; 107 | webView.setVisibility(View.GONE); 108 | customViewContainer.setVisibility(View.VISIBLE); 109 | customViewContainer.addView(view); 110 | customViewCallback = callback; 111 | } 112 | 113 | @Override 114 | public View getVideoLoadingProgressView() { 115 | 116 | if (mVideoProgressView == null) { 117 | LayoutInflater inflater = LayoutInflater.from(MyActivity.this); 118 | mVideoProgressView = inflater.inflate(R.layout.video_progress, null); 119 | } 120 | return mVideoProgressView; 121 | } 122 | 123 | @Override 124 | public void onHideCustomView() { 125 | super.onHideCustomView(); //To change body of overridden methods use File | Settings | File Templates. 126 | if (mCustomView == null) 127 | return; 128 | 129 | webView.setVisibility(View.VISIBLE); 130 | customViewContainer.setVisibility(View.GONE); 131 | 132 | // Hide the custom view. 133 | mCustomView.setVisibility(View.GONE); 134 | 135 | // Remove the custom view from its container. 136 | customViewContainer.removeView(mCustomView); 137 | customViewCallback.onCustomViewHidden(); 138 | 139 | mCustomView = null; 140 | } 141 | } 142 | 143 | class myWebViewClient extends WebViewClient { 144 | @Override 145 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 146 | return super.shouldOverrideUrlLoading(view, url); //To change body of overridden methods use File | Settings | File Templates. 147 | } 148 | } 149 | 150 | } 151 | --------------------------------------------------------------------------------