2

我正在尝试添加视频标签并将MediaElement.js应用于它。

如果我这样做,它可以正常工作(为简洁起见减少了 Video 标签,但不会引发任何错误):

<link rel='stylesheet' href='/_layouts/MediaElementWebPart/mediaelementplayer.min.css' />
<script type="text/javascript" src='/_layouts/MediaElementWebPart/jquery.js'></script>
<script type="text/javascript" src='/_layouts/MediaElementWebPart/mediaelement-and-player.min.js'></script>
<video width='640' height='320' id='MEWP'>
</video>
<script>$('MEWP').mediaelementplayer()</script>

但是,如果我通过代码添加标签,.mediaelementplayer() 会抛出 SCRIPT438: Object doesn't support property or method 'mediaelementplayer'

<link rel='stylesheet' href='/_layouts/MediaElementWebPart/mediaelementplayer.min.css' />
<script type="text/javascript" src='/_layouts/MediaElementWebPart/jquery.js'></script>
<script type="text/javascript" src='/_layouts/MediaElementWebPart/mediaelement-and-player.min.js'></script>
<div id="videosContainer">
</div>
<script type="text/javascript">
    $(function () {
        var random = Math.floor((Math.random() * 100000) + 1);
        var id = "MEWP-" + random.toString();
        var video = "<video width=\'640\' height=\'320\' id=\'" + id + "\' ></video>";
        $(video).appendTo('#videosContainer');
        $('#' + id).mediaelementplayer();
    });
</script>

不过,根据调试器,似乎找到了视频标签的元素

[+]     $('#' + id)[0]  {...}   [Object, HTMLVideoElement]

我在这里想念什么?任何有关解决此类问题的一般建议,不胜感激。

4

0 回答 0