Javascript API not working for Chrome or Safari on JW Player 5.9

为君一笑 提交于 2019-12-01 23:33:06

问题


I am working on a custom interface for the JW Player which displays the current track title and has play/pause, next track, previous track and volume toggle buttons.

It works for IE8/9 and FF but fails for Chrome and Safari. Chrome's console gives the following error: Uncaught TypeError: Object # has no method 'addControllerListener'

This is the code I am using for testing.

<div id="container">Loading the player ...</div>
<script type="text/javascript">
    jwplayer("container").setup({
        image: "preview.jpg",
        height: 320,
        width: 480,
        modes: [
            { type: "html5" },
            { type: "flash", src: "player.swf" }
        ],
        'playlist': [
            { 'file': "audio/01.mp3", 'title': "Track 1" },
            { 'file': "audio/02.mp3", 'title': "Track 2" },
            { 'file': "audio/03.mp3", 'title': "Track 3" }
        ],
    });

    function playerReady(obj)
    {
        player = document.getElementById(obj.id);
        displayFirstItem();
    };

    function displayFirstItem()
    {
        try
        {
            playlist = player.getPlaylist();
        }
        catch(e)
        { 
            setTimeout("displayFirstItem()", 100);
        }

        player.addControllerListener('ITEM', 'itemMonitor');
        itemMonitor({index:0});
    };

    function itemMonitor(obj)
    {
        $('#nowplaying').html('<span><strong>Now Playing:</strong> ' + playlist[obj.index]['title'] + '</span>');
    };
</script>
<div id="nowplaying"></div>
<div class="control_bar">
    <ul>
         <li onclick='player.sendEvent("play");'>[ &#8250; ] Play / Pause</li>
         <li onclick='player.sendEvent("prev");'>[ &laquo; ] Previous item</li>
         <li onclick='player.sendEvent("next");'>[ &raquo; ] Next item</li>
    </ul>
</div>

I have searched and tried several modifications, like adding the javascriptid parameter, nothing seems to work for Chrome or Safari.

Any ideas? Thanks


回答1:


Short

Remove { type: "html5" },.

Long

HTML5 renders the player with divs and img tags and plays your videos and it doesn't support everything the flash version supports, including parts of the JS API.



来源:https://stackoverflow.com/questions/9809438/javascript-api-not-working-for-chrome-or-safari-on-jw-player-5-9

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