Kri*_*ris 5 java android webview
当我在我的Android设备的默认网络浏览器上查看此页面并单击第一个视频时,它会触发我设备的默认视频播放器.它加载和播放.
但是,当我使用WebView在我的应用程序中查看相同的链接时,它不会打开默认的视频播放器.可能是什么问题呢?
我正在使用此链接中的webview代码.
我也像在文档中所说的那样在全屏模式下制作webview ,使用此代码全屏:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
编辑:我现在使用以下代码,但仍然没有工作,任何想法?
package com.example.Playmp4OnWebView;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class PlayMp4OnWebView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
WebView webview = new WebView(this);
setContentView(webview);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webSettings.setPluginsEnabled(true);
webSettings.setAllowFileAccess(true);
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.endsWith(".mp4")){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); //warning no error handling will cause force close if no media player on phone.
return true;
}
else return false;
}});
//This will load the webpage that we want to see
webview.loadUrl("http://www.broken-links.com/2010/07/30/encoding-video-for-android/");
}
}
Run Code Online (Sandbox Code Playgroud)
如果您检测到具有支持的视频 mimetype 的 URL 返回 true,则必须附加自己的WebViewClient并覆盖,然后使用该 URL 启动默认活动。shouldOverrideUrlLoading()这是一个未经测试的样本。
mWebView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(Webview view, String url){
if(url.endsWith(".mp4") || url.endsWith("some other supported type")){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); //warning no error handling will cause force close if no media player on phone.
return true;
}
else return false;
}});
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
11369 次 |
| 最近记录: |