【问题标题】:YouTube video in an iframe continues to play after navigation - Android and Phonegap导航后 iframe 中的 YouTube 视频继续播放 - Android 和 Phonegap
【发布时间】: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


    【解决方案1】:

    我也遇到了同样的问题。我使用的解决方法是覆盖 onBackPressed() 并在播放视频的同一 web 视图中加载“about:blank”。非常适合我!试试看。祝你好运:-)

    -Yogesh

    【讨论】:

    • 谢谢,但您知道如何将用户重定向到引用页面吗?
    猜你喜欢
    • 1970-01-01
    • 2013-07-27
    • 2013-05-23
    • 2017-09-22
    • 2015-02-26
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 2011-06-26
    相关资源
    最近更新 更多