JWPlayer - undefined is not a function

不羁的心 提交于 2020-01-01 10:13:19

问题


Im wondering if someone could help me out.

Im trying to load a video using jwplayer but am getting errors.

This is the code im using.

        <script type="text/javascript">
            jwplayer("legacyPlayer").setup({
                width:370,
                height:240,
                file: "https://s3.amazonaws.com/legacy/videoname.mp4",
            });
        </script>

        <div id="legacyPlayer" align="center"></div>

The error my console is showing is as follows:

Uncaught TypeError: undefined is not a function 

Any help getting this working would be greatly appreciated.

Cheers,


回答1:


You should put script block after the HTML tag, looks like this:

<div id="legacyPlayer" align="center"></div>
<script type="text/javascript">
    jwplayer("legacyPlayer").setup({
        width:370,
        height:240,
        file: "https://s3.amazonaws.com/legacy/videoname.mp4",
    });
</script>

When browser document parser encounters a script tag, it will stop parsing the other html content on your page until the script is downloaded and executed. It means that "legacyPlayer" is not exist when you try to manipulate it in the script block. That's the root cause of "undefined is not a function" error (jwplayer selector can't find a DOM with ID:legacyPlayer).




回答2:


Make sure that your div id ="container" is equal to jwplayer('container') name

<div id="container">Loading the player...</div>

    <script type="text/javascript">

        var playerInstance = jwplayer('container');
        playerInstance.setup({
            file: "//content.jwplatform.com/videos/3XnJSIm4-640.mp4",
            image: "//content.jwplatform.com/thumbs/3XnJSIm4-640.jpg",
            width: 640,
            height: 270,
            logo: {
                file: "//content.jwplatform.com/watermarks/gdz4zR4a.png",
                link: "//www.blender.org/foundation/"
            },
            abouttext: 'Video Available at Blender.org',
            aboutlink: 'http://www.blender.org'
        });
    </script>

</div>


来源:https://stackoverflow.com/questions/24690481/jwplayer-undefined-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!