将 YouTube 视频嵌入 libGDX 项目

Embed YouTube video into libGDX project

我想在我的应用程序中嵌入 YouTube 视频吗?我找不到有关此主题的任何信息。是否有为此目的指定的方法?

不,清除 libGDX 是不可能的。这取决于您开发应用程序的平台。

如果目标是Android,你必须再做一个activity,从libGDx开始。在那里你实现了 webview,它将包含你的 YouTube 视频的 url。在 libGDX 中按下按钮(或任何事件)后,应用程序 activity 可以启动并且后台将进入休眠状态。

activity 的示例,它打开对话框并创建 webView:

public class WebVideo extends Activity {

    private String url;    

    public WebVideo(String url) {    
        this.url = url;     

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();    
        WebView webview = null;    
        // if we have internet connection
        if (common.IsNetworkAvailable()) {
            setContentView(R.layout.activity_list_item);

            // initialize web view
            webview = (WebView) this.findViewById(R.id.widget_frame);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings()
                    .setJavaScriptCanOpenWindowsAutomatically(true);
            webview.setBackgroundColor(color.black);
            // loar url of questionnare
            webview.loadUrl(url);
            webview.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }

                @Override
                public void onPageStarted(WebView view, String url,
                        Bitmap favicon) {

                }
            });
        }
        // if we dont have connection, show dialog and end activity
        else {
            buildDialog(this).show();
        }    
    }

    // show alert dialog
    private AlertDialog.Builder buildDialog(Context c) {    
            //Maybe we want some alert dialog (implementation here)
            }
        });    
        return builder;
    }   

    private void finishActivity() {
        // some result after exit if we want    
        this.finish();
    }
}

如果你的目标是iOS,我相信,也有类似的处理方式。 Html:您仍应在同一浏览器中打开视频。 关键是 Desktop,据我所知,不可能用一些明确的方法伪造它。

我在这里找到了一个看似不错的解决方案:https://github.com/libgdx/gdx-video这是一个视频渲染扩展,正在持续开发中。