您的位置:首页 > 移动开发

ANDROID webview解决视频无法播放问题

2017-04-20 08:25 1101 查看

ANDROID webview解决视频无法播放问题

———-本人原创,转载请标注—————

android关于webview的用法应该不需要过多解释了。这里我也不再多费大家时间了。但经常会碰到用webview即使添加了对js的支持并且添加了硬件加速后,依旧无法播放视频的现象,但浏览器就可以。在这我说下最近开发过程中的解决方案:

此次解决主要依靠tencentwebview

1.layout中添加tencentwebview:

<com.tencent.smtt.sdk.WebView
android: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";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.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 stub
tencent_webview = (WebView) findViewById(R.id.tencent_webview);
tencent_webview.loadUrl(url);
WebSettings webSettings = tencent_webview.getSettings();
webSettings.setJavaScriptEnabled(true);
tencent_webview.setWebViewClient(new WebViewClient() {
@Override
public 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐