1

我有以下代码。它成功地从 YouTube 流式传输视频。但是当视频结束时。它无法再次播放,即使我退出并重新进入应用程序也是如此。它总是显示加载页面,然后立即跳转到建议的视频。

public class HdPlayer extends CustomView {
Button share_btn;
DisplaySize mDisplaySize;
String youtubeLink = null;
String thumbnailLink, description, VideoId, viewCount, date = null;
String title = null;
WebView webview;
String duration = null;

DbAdapter db;

/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
    // Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hd_player);
    db = new DbAdapter(this);

    titlebar_title.setText("Playing");
    titlebar_icon.setImageResource(R.drawable.titlebar_play);
    Bundle bundle = this.getIntent().getExtras();
    youtubeLink = bundle.getString("youtubeLink");


    webview = (WebView) findViewById(R.id.web_view_player);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setPluginState(PluginState.ON);
    webview.getSettings().setPluginsEnabled(true);
    // webview.getSettings().setLoadWithOverviewMode(true);// completely zoomed out
    // webview.getSettings().setUseWideViewPort(true);
    webview.getTouchables();

    webview.setBackgroundColor(Color.parseColor("#00000000"));
    mDisplaySize = new DisplaySize(this);

    Display display = getWindowManager().getDefaultDisplay();
    int[] widthHeight = new int[2];
    widthHeight = mDisplaySize.getDisplaySize(display);
    int width = widthHeight[0];
    int height = widthHeight[1];
    Log.i("iframe", " before iframe");
    String emdLink = "http://www.youtube.com/embed/" + VideoId;
    Log.i("iframe", " before loadData, youtubeLink: " + emdLink);

    LayoutParams lp = new RelativeLayout.LayoutParams(width,
            (width / 4) * 3);
    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    webview.setLayoutParams(lp);
    webview.setWebChromeClient(new WebChromeClient());
    webview.loadUrl(emdLink);


}

@Override
public void onPause() {
    super.onPause();

    try {
        Log.i("in onpause", "onpause try" );
        Class.forName("android.webkit.WebView")
                .getMethod("onPause", (Class[]) null)
                .invoke(webview, (Object[]) null);

    } catch (ClassNotFoundException cnfe) {
    } catch (NoSuchMethodException nsme) {
    } catch (InvocationTargetException ite) {
    } catch (IllegalAccessException iae) {
    }
    webview.clearCache(true);
    webview.clearHistory();
    webview.destroy();
}




}

它报告错误: dequeueBuffer: SurfaceComposer::createGraphicBuffer failed

4

1 回答 1

1

以下代码对我来说很好。尝试添加这个
webView.setWebViewClient(new WebViewClient());

webView.setWebChromeClient(new WebChromeClient(){

});
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.getTouchables();
webView.setBackgroundColor(Color.parseColor("#00000000"));
String emdLink = "http://www.youtube.com/embed/" + "hPUGNCIozp0";
webView.loadUrl(emdLink);
于 2012-10-18T05:47:31.173 回答