1
我正在嘗試構建一個帶有webview的應用,允許YouTube播放。 現在youtube的網站正在加載,我可以點擊視頻,但我能聽到的只是它的聲音,看不到任何東西。真的很感謝在這個問題上的一些幫助。該應用程序已加載到三星Galaxy S上。 SDK版本8.嵌入YouTube視頻的網絡視圖
import com.keyes.youtube.OpenYouTubePlayerActivity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class Youtube extends Activity {
private WebView mWebView;
private String extra;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
extra = getIntent().getStringExtra("VideosId");
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setLoadWithOverviewMode(true);// completely zoomed out
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getTouchables();
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
mWebView.setWebViewClient(new ourViewClient());
mWebView.loadUrl("http://www.youtube.com/watch?v=AIbHWcko0Mg&feature=g-all-bul");
mWebView.setWebViewClient(new ourViewClient());
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
您的意思是您給出的代碼在API不到11的時候不起作用?我想加載youtube視頻在Api8上[我的問題](http://stackoverflow.com/questions/14156411/loading-youtube-video-through-i-frame-in-android-web查看)你可以看看這個 – edwin 2013-01-05 11:00:11