Testhtml5webview.java :
package o.html5webview; import android.app.Activity; import android.content.res.Configuration; import android.os.Bundle; import android.view.KeyEvent; public class TestHTML5WebView extends Activity { HTML5WebView mWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mWebView = new HTML5WebView(this); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { //mWebView.loadUrl("http://freebsd.csie.nctu.edu.tw/~freedom/html5/"); mWebView.loadUrl("file:///android_asset/video.html"); } setContentView(mWebView.getLayout()); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mWebView.saveState(outState); } @Override public void onStop() { super.onStop(); mWebView.stopLoading(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mWebView.inCustomView()) { mWebView.hideCustomView(); return true; } } return super.onKeyDown(keyCode, event); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } }
-------------------------------------------------------------------------------
html5webview.java
package o.html5webview; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Bundle; import android.os.PowerManager; import android.view.KeyEvent; public class TestHTML5WebView extends Activity { HTML5WebView mWebView; @SuppressWarnings("deprecation") @SuppressLint("Wakelock") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mWebView = new HTML5WebView(this); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); wl.acquire(); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { //mWebView.loadUrl("http://freebsd.csie.nctu.edu.tw/~freedom/html5/"); mWebView.loadUrl("file:///android_asset/video.html"); } setContentView(mWebView.getLayout()); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mWebView.saveState(outState); } @Override public void onStop() { super.onStop(); mWebView.stopLoading(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mWebView.inCustomView()) { mWebView.hideCustomView(); return true; } } return super.onKeyDown(keyCode, event); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } }
----------------------------------------------------------------------------------------------------------------------------------
asset/video.html :
<!DOCTYPE html> <html> <head> <title> Video Test 3 </title> </head> <body> <divstyle="text-align:center;"> <videosrc="http://184.72.239.149/vod/smil:bigbuckbunny.smil/playlist.m3u8"width=640height=480 poster=html5.png controls> html5 video </video> </div> <script> video = document.getElementsByTagName("video")[0]; </script> <p> <divstyle="text-align:center;"> <buttononClick="video.play()"> ▶ </button> <buttononClick="video.pause()"> ◼ </button> <buttononclick="video.volume += 0.25">Volume Up</button> <buttononclick="video.volume -= 0.25">Volume Down</button> <buttononclick="video.muted = true">Mute</button> <buttononclick="video.muted = false">Unmute</button> </div> </body> </html>
-------------------------------------------------------------------------------------------------------------------------------
AndroidManifest.xml
<?xmlversion="1.0"encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.itri.html5webview" android:versionCode="1" android:versionName="1.0"> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission>> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /> <uses-permission android:name="android.permission.ACCESS_LOCATION" /> <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17"/> <application android:icon="@drawable/icon" android:label="@string/app_name" android:hardwareAccelerated="true" android:allowBackup="true" android:configChanges="orientation"> <activity android:name=".TestHTML5WebView" android:screenOrientation="landscape" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
文章標籤
全站熱搜
留言列表