在删除< video>之后,音频继续Chrome中的元素 [英] Audio continues after removing <video> element in Chrome

查看:107
本文介绍了在删除< video>之后,音频继续Chrome中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome中的视频支持有问题.我的网页必须在Chrome中运行,并且我正在使用以下代码定期检查该网页是否必须播放视频...但是问题是,删除该元素后,我仍然可以听到声音以及何时听到声音重新创建元素,新视频的音频和旧的重叠部分.

I am having issues with video support in Chrome. My web page must run in Chrome and I am using the following code to check periodically if the web page has to play a video or not... but the problem is that after I remove the element, I still hear the audio and when I recreate the eleemnt, the audio of the new video and the old overlaps.

function showVideo() {
        var video = videodata;

        var videobox = $('#videobox').first();
        var videoplayer = $('#videoplayer').first();

        if (video.Enabled) {
            if ((videoplayer.length > 0 && videoplayer[0].currentSrc != video.Location) || videoplayer.length == 0) {
                videobox.empty();
                videobox.append('<video id="videoplayer" preload="auto" src="' + video.Location + '" width="100%" height="100%" autoplay="autoplay" loop="loop" />');
                videobox.show();
            }
        } else {
            videobox.hide();
            videobox.empty(); // Clear any children.
        }
    }

我该如何解决?

谢谢.

推荐答案

以下是我要使其正常工作所必需的最低要求.当用户按下后退按钮时生成ajax请求时,由于缓冲,我实际上遇到了停顿.在Chrome和Android浏览器中暂停视频可保持其缓冲.非异步ajax请求将被阻塞,等待缓冲完成,这是永远不会发生的.

The following was the minimum I had to go to get this to work. I was actually experiencing a stall due to the buffering while spawning ajax requests when the user pressed the back button. Pausing the video in Chrome and the Android browser kept it buffering. The non-async ajax request would get stuck waiting for the buffering to finish, which it never would.

将此内容绑定到beforepagehide事件中即可解决此问题.

Binding this to the beforepagehide event fixed it.

 $("#SOME_JQM_PAGE").live("pagebeforehide", function(event)
 {
           $("video").each(function () 
           { 
               logger.debug("PAUSE VIDEO");
               this.pause();
               this.src = "";
           });
 });

这将清除页面上的每个视频标签.

This will clear every video tag on the page.

这篇关于在删除&lt; video&gt;之后,音频继续Chrome中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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