【发布时间】:2013-01-30 17:46:21
【问题描述】:
问题类似于在 Windows 8 上提出的YouTube video in an iframe in Webview continues to play after navigation
我正在使用 Phonegap 创建一个 Android 应用程序。 我能够使用 Childbrowser 插件并借助 Youtube iframe 代码显示一个 Youtube 视频,该代码存在于我的服务器上的一个 php 文件中。
但是,如果用户点击后退按钮,则会显示应用程序屏幕并且您可以听到视频的声音。
调用子浏览器的代码如下:
$('#videobutton').attr('onclick', 'javascript:window.plugins.childBrowser.showWebPage("http://example.com/sundeep/video.php?trailer='+trailer+'", { showLocationBar: false });');
我知道要关闭childbrowser你需要放置以下代码:
window.plugins.childBrowser.onClose();
但是我不知道上面的代码放在哪里。
解决方法 我什至尝试了一种解决方法,方法是使用 childbrowser 打开包含 iframe 代码的本地页面(video.html),如下所示:
$('#videobutton').attr('onclick', 'javascript:window.plugins.childBrowser.showWebPage("file:///android_asset/www/video.html", { showLocationBar: false });');
并使用 window.localStorage.setItem 我能够传递和显示视频。我有下面的代码,理论上应该可以解决原始问题但不起作用:
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-2.3.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to call Cordova methods
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
window.plugins.childBrowser.onClose();
}
</script>
- Apache Cordova (Phonegap) - 2.3.0 Jquery Mobile - 1.2 Android - Jelly 豆(4.2)
感谢任何帮助!真的坚持这个。
【问题讨论】:
标签: android cordova jquery-mobile youtube childbrowser