我正在尝试构建一个带有 webview 的应用程序,它允许 youtube 播放。现在 youtube 的网站正在加载,我可以点击视频,但我只能听到它的声音,看不到任何东西。非常感谢您在这个问题上提供一些帮助。该应用程序已加载到 samsung galaxy s 上。版本 8。
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);
}
}