【发布时间】:2011-06-06 01:46:01
【问题描述】:
当我在我的 android 设备的默认网络浏览器上查看 this page 并单击第一个视频时,它会触发我设备的默认视频播放器。它加载并播放。
但是,当我使用 WebView 在我的应用中查看相同的链接时,它不会打开默认的视频播放器。可能是什么问题?
我正在使用this link 中的 webview 代码。
我还像docs 中所说的那样将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/");
}
}
【问题讨论】: