如何暂停或当你离开一个选项卡视图停止iframe的YouTube视频或最大限度地减少您的应用程序离子 [英] How to pause or stop an iframe youtube video when you leave a tab view or minimise your Ionic App

查看:366
本文介绍了如何暂停或当你离开一个选项卡视图停止iframe的YouTube视频或最大限度地减少您的应用程序离子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个离子应用程序,我要部署到Android Play商店,我的应用程序只是有视频1选项卡的列表,那么当你在视频的1单击然后使用播放视频的另一个选项卡IFRAME这样

I have a Ionic App that I want to deploy to the android play store, my app just has a list of videos on 1 tab, then when you click on 1 of the video it then plays the video in another tab using an iframe like this

<div class="video-container">
    <iframe id="VideoPlayer" ng-src="{{getIframeSrc(videoid)}}" frameborder="0" width="560" height="315" allowfullscreen></iframe>
</div>

这一切工作正常。这个问题是由于谷歌YoutubeAPI Play商店政策,你不能让你的应用程序中发挥的背景YouTube视频或音频,例如,当您减少应用或移动到另一个选项卡。

This all works fine. The issue is due to YoutubeAPI Google Play Store policy you are not allowed to allow your app to play the youtube video or audio in the background, for example when you minimise your app or move to another tab.

什么是实现这一目标的最佳途径?我需要确保当你最小化或者移动到另一个选项卡,它会从如果用户一直没有停止过它自己的iframe停止播放YouTube视频。

What is the best way to achieve this? I need to make sure when you minimise or move to another tab, it will stop the youtube video from playing from the iframe if the user hasn't stopped it themselves.

*******更新********

*******UPDATE********

我现在可以通过一个按钮调用此函数停止视频

I can now stop the video by calling this function using a button

$scope.stopVideo = function() {

 var iframe = document.getElementsByTagName("iframe")[0].contentWindow;

   iframe.postMessage('{"event":"command","func":"' + 'stopVideo' +   '","args":""}', '*');
}

然而,当我使用离子即成,如果我在Android手机上运行相同的code测试这只作品中,我得到参考错误:DIV未定义。不知道为什么会在浏览器中运行,但不能在应用程序时,它在Android中运行。

However this only works when I test it using Ionic Serve, if I run the same code on an android phone, I get Reference Error: Div Not Defined. Not sure why this would work in browser, but not on the app when it is run in Android.

我也仍然需要离子了解如何调用该功能,你可以不看应用程序的每个场景,因此关闭应用的背景下,去一个新的选项卡,preSS后退按钮...有没有一种方法,我可以添加到被用于所有这些情况下这个功能呢?

I also still need to understand in Ionic how to call this function for every scenario where you may not be looking at the app, so for closing the app to the background, going to a new tab, press back button... Is there a way I can add this function to be called for all these scenarios?

推荐答案

我设法得到这个工作使用YouTube上面的方法,并在科尔多瓦框架和$ ionicView.beforeLeave事件暂停事件这样描述。

I managed to get this working using the youtube method described above and doing this in the Pause event in the cordova framework and the $ionicView.beforeLeave event.

这篇关于如何暂停或当你离开一个选项卡视图停止iframe的YouTube视频或最大限度地减少您的应用程序离子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆