Android:在我的应用程序内播放 YouTube 视频
我希望有人能为我澄清事实。我知道有很多关于这个问题的帖子,但我仍然不清楚。
我希望我的应用程序显示书本页面的图像,并在该图像内播放 YouTube 视频。显然,我应该为此使用 WebView。
WebView mWebView = new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new HelloWebViewClient());
setContentView(mWebView);
String Play = "<iframe width=\"600\" height=\"400\" src=\"http://www.youtube.com /embed/VCDOjdYhj1Y\" frameborder=\"10\"</iframe>";
mWebView.loadData(Play, "text/html", "utf-8");
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
当我这样做时,视频看起来不错,但声音滞后。如果有人说话,因为单词与他们的嘴唇不匹配,这是非常明显的。据我了解, WebView 实际上并不是用于显示视频,尽管它受支持,它只是在应用程序内部显示网页的一种方式,最好没有用户交互,如果您想要视频和网页,则应该使用以下命令启动浏览器。一个意图。我不想这样做,因为我没有直接指向视频文件,
所以我没有选择吗?在 HTML 视图中嵌入 YouTube 视频在 iPhone 应用程序中效果非常好,我希望有人能给我最后的决定,谢谢!
I'm hoping someone can set the record straight for me. I know there are several posts about this issue, but I'm still unclear about this.
I want my application to show an image of a page out of a book, and inside that image I want to play a youtube video. Apparently, I"m supposed to use a WebView for this.
WebView mWebView = new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new HelloWebViewClient());
setContentView(mWebView);
String Play = "<iframe width=\"600\" height=\"400\" src=\"http://www.youtube.com /embed/VCDOjdYhj1Y\" frameborder=\"10\"</iframe>";
mWebView.loadData(Play, "text/html", "utf-8");
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
When I do this, the video looks okay but the sound is lagging. It's very noticeable if someone is talking because the words don't match their lips. From what I understand, WebView really isn't meant for showing video even though it's supported. It's simply a way of showing a web page inside of the app with preferably no user interaction. If you want video and web pages, you're supposed to launch the browser with an Intent. I don't want to do this. I can't use a VideoView because I'm not pointing directly to a video file.
So is that it? Am I out of options? You'd think Youtube and Android would be very compatible since their both Google. Embedding a youtube video in an HTML View works really well in iPhone apps. I hope someone can give me the final word on this. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道这与 url 的加载方式(如父母等)有关吗?
Can't it is something with how the url is loaded like parents, etc.