我有這段代碼,當在模擬器上運行時打印日誌消息在shouldOverrideUrlLoading方法,當我點擊視頻像 06-04 08:53:24.295:VERBOSE/url(502 ):vnd.youtube:aEb80IUiLog?vndapp=youtube_mobile & vndclient = MV-谷歌& vndel =輪廓使用webview播放YouTube視頻的問題
但是當我測試這對我的HTC Desire,日誌信息犯規露面,因此無法播放視頻。我在這裏錯過了什麼。設備原生android瀏覽器播放所有youtube視頻。
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
WebView web=(WebView) findViewById(R.id.webkitWebView1);
// web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setJavaScriptEnabled (true);
// web.getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
// web.getSettings().setPluginsEnabled (true);
// web.getSettings().setSupportMultipleWindows (false);
// web.getSettings().setSupportZoom (false);
// web.setVerticalScrollBarEnabled (false);
// web.setHorizontalScrollBarEnabled (false);
// web.getSettings(). setAppCacheEnabled(true);
// web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.loadUrl("http://www.youtube.com/cg225");
web.setWebViewClient(new WebViewClient()
{
@ Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.v("url",url);
// YouTube video link
if (url.startsWith("vnd.youtube:"))
{
int n = url.indexOf("?");
if (n > 0)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s", url.substring("vnd.youtube:".length(),n)))));
}
return (true);
}
return (false);
}
});
}catch(Exception e){
e.printStackTrace();
}
}
}