当 Popover 关闭时使 Youtube 停止播放,或使用 Javascript Youtube 控件

发布于 2024-09-16 19:10:16 字数 587 浏览 4 评论 0原文

因此,我在弹出窗口中实现 YouTube 视频时遇到了一些问题。我可以让 YouTube 视频正常播放,但是当用户单击弹出窗口(销毁它)时,声音会继续播放。我的解决方案是让显示 youtube 视频的 webview 在 vi​​ewDidDisappear 方法中加载一个空白的 html 字符串,这效果很好。

但是,我现在遇到一个问题,如果用户按下 YouTube 视频上的全屏按钮,YouTube 视频确实会全屏显示,但弹出窗口位于其前面。这很烦人,但用户通常只需单击屏幕的其他部分,它就会消失。我愿意忍受这一点。当然,除了......调用viewDidDisappear,没有加载任何内容到html中,炸毁了我的整个应用程序。

我想知道是否有人知道如何在 webview 中加载一些可以控制 youtube 视频的 javascript。通过这种方式,我可以让 viedDidDiappear 调用暂停,这样当弹出窗口关闭时声音就不会继续播放,并且 YouTube 视频也不会全屏播放。

这不是理想的解决方案(因为弹出窗口仍然处于全屏状态),但我现在就采用它。如果有人可以帮助我需要的 javascript 注入,或者提出更好的解决方案,我将不胜感激。

So I've run into some problems implementing YouTube videos in popovers. I can get the YouTube video to play just fine, but when the user clicks off the popover (destroying it), the sound continues playing. My solution for this was to have the webview that was displaying the youtube video load a blank html string in the viewDidDisappear method, and this works great.

However, I am now running into an issue where if the user pushes the fullscreen button on the youtube video, the youtube video does indeed go fullscreen, but the popover is in front of it. This is annoying, but the user could normally just click some other portion of the screen and it goes away. I would be willing to live with this. Except of course.....that calls viewDidDisappear, loading nothing into the html, blowing up my entire application.

I was wondering if anyone knew how to load some javascript in the webview that could control the youtube video. In this way, I could have viedDidDiappear call the pause, so the sound would not continue playing when the popover is dismissed, and the youtube video would not blow up in full screen.

This is not the ideal solution (since the popover still sits in the way in full screen), but I will take it for now. If anyone could help with the javascript injection I would need, or suggest an even better solution, I would greatly appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文