当我在我的android设备默认的浏览器上查看这个页面并点击第一个视频时,它会触发我的设备的默认视频播放器。它加载并播放。
然而当我在我的应用程序中使用WebView查看相同的链接时,它不会打开默认的视频播放器。可能出了什么问题?
我正在使用此链接中的webview代码。
我还按照文档所说的将webview设置为全屏模式,并使用以下代码进入全屏:
然而当我在我的应用程序中使用WebView查看相同的链接时,它不会打开默认的视频播放器。可能出了什么问题?
我正在使用此链接中的webview代码。
我还按照文档所说的将webview设置为全屏模式,并使用以下代码进入全屏:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
编辑:我现在使用以下代码,但仍然不起作用,有任何想法吗?
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/");
}
}