ANDROID webview解决视频无法播放问题
生活随笔
收集整理的這篇文章主要介紹了
ANDROID webview解决视频无法播放问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ANDROID webview解決視頻無法播放問題
———-本人原創,轉載請標注—————
android關于webview的用法應該不需要過多解釋了。這里我也不再多費大家時間了。但經常會碰到用webview即使添加了對js的支持并且添加了硬件加速后,依舊無法播放視頻的現象,但瀏覽器就可以。在這我說下最近開發過程中的解決方案:
此次解決主要依靠tencentwebview
1.layout中添加tencentwebview:
<com.tencent.smtt.sdk.WebViewandroid:id="@+id/tencent_webview"android:layout_width="match_parent"android:layout_height="match_parent" />2.activity代碼:
public class TestActivity extends Activity{private com.tencent.smtt.sdk.WebView tencent_webview;private String url = "http://www.baidu.com";@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.testactivity_main);getWindow().setFormat(PixelFormat.TRANSLUCENT);getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);init();}@SuppressLint("SetJavaScriptEnabled")private void init() {// TODO Auto-generated method stubtencent_webview = (WebView) findViewById(R.id.tencent_webview);tencent_webview.loadUrl(url);WebSettings webSettings = tencent_webview.getSettings();webSettings.setJavaScriptEnabled(true);tencent_webview.setWebViewClient(new WebViewClient() {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);return true;}});} }3.在AndroidManifest.xml中對對應的activity配置硬件加速:
android:hardwareAccelerated="true"問題到此解決
注:這里要導入tencentwebview的jar包
http://download.csdn.net/detail/eulinze/9819434
總結
以上是生活随笔為你收集整理的ANDROID webview解决视频无法播放问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何做SEO(关键词)
- 下一篇: PHP获取带中英文括号的内容