该问题类似于在 Windows 8 上询问导航后 Webview 中 iframe 中的 YouTube 视频继续播放
我正在使用 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 bean (4.2)
任何帮助表示赞赏!真的卡在这个了。