【发布时间】:2011-06-04 16:26:18
【问题描述】:
我有这段代码,当我在模拟器上运行时,当我点击视频时会打印出 shouldOverrideUrlLoading 方法中的日志消息 06-04 08:53:24.295: 详细/url(502): vnd.youtube:aEb80IUiLog?vndapp=youtube_mobile&vndclient=mv-google&vndel=profile
但是当我根据我的 htc 需求进行测试时,日志消息没有显示,因此无法播放视频。我在这里缺少什么。设备原生安卓浏览器播放所有 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();
}
}
}
【问题讨论】: