Prevent divx web plugin fron replacing html5 video element?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 08:47:39

I got around this by putting an empty HTML 5 video tag, then putting in the video source tags in a JavaScript function in the body onload event. The video then comes up in the normal HTML 5 player and not the DivX web player.

e.g. This would give the DivX player:

<video width="320" height="240" controls="controls">
  <source src="movie.mp4" type="video/mp4" />
</video>

But this would give the normal html 5 player:

    <head>
    <script type="text/javascript">
    function changevid() {
       document.getElementById('vid').innerHTML = '<source src="inc/videos/sample1.mp4" type="video/mp4" />';
       document.getElementById('vid').load();
    }
    </script>
    </head>
    <body onload="changevid()">

       <video id="vid" width="800" height="450" controls="controls">    
       </video>

    </body>

At this time, there is no API or means to block the divx plugin from replacing video elements with their placeholder. :-(

i started reverse-engineering the divx-plugin to find out what can be done to hack a way into disabling it. An example, including the complete sourcecode of the divx-plugin, can be found here: http://jsfiddle.net/z4JPB/1/

It currently appears to me that a possible solution could work like this:

  • create a "clean" backup of the methods appendChild, replaceChild and insertBefore - this has to happen before the content-script from the chrome-extension is executed.
  • the content-script will execute, overrides the methods mentioned above and adds event-listeners to the DOMNodeInsertedIntoDocument and DOMNodeInserted events
  • after that, the event-listeners can be removed and the original DOM-Methods restored. You should now be able to replace the embed-elements created by the plugin with the video-elements

It seems, that the plugin is only replacing the video when there are src elements within the video tag. For me it worked by first adding the video tag, and then - in a second thread - add the src tags. However, this doesn´t work in IE but IE had no problem with an insertion of the complete video tag at once.

So following code worked for me in all browsers (of course, jQuery required):

var $container = $('video_container');
var video = 'my-movie';
var videoSrc = '<source src="video/'+video+'.mp4" type="video/mp4"></source>' +
    '<source src="video/'+video+'.webm" type="video/webm"></source>' +
    '<source src="video/'+video+'.ogv" type="video/ogg"></source>';

if(!$.browser.msie) {
    $container.html('<video autoplay loop></video>');
    // this timeout avoids divx player to be triggered
    setTimeout(function() {
        $container.find('video').html(videoSrc);
    }, 50);
}
else {
    // IE has no problem with divx player, so we add the src in the same thread
    $container.html('<video autoplay loop>' + videoSrc + '</video>');
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!