我想将 YouTube 视频嵌入到我的应用程序中吗?我找不到关于这个主题的任何内容。有没有具体的方法来达到这个目的?
最佳答案
不,使用清晰的 libGDX 是不可能的。这取决于您开发应用程序的平台。
如果目标是Android,您必须创建另一个从libGDx启动的事件。在那里你实现了 webview,它将包含你的 YouTube 视频的 url。按下 libGDX 中的按钮(或任何事件)后,应用程序事件可以启动,后台将休眠。
事件示例,打开对话框并创建 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:您仍应在同一浏览器中打开视频。 关键是桌面,据我所知,不可能用一些明确的方法来伪造它。
关于youtube - 将 YouTube 视频嵌入 libGDX 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29580318/