0

我从 Twitch 获取流并通过 jQuery 动态更新流信息。它适用于 Firefox,但不适用于 Chrome / IE。

Javascript:

$(function() { 
    var streamer = $("#stream-list ul li.active").first().attr("id");
    $("#live_embed_player_flash").attr("data", "http://sv.twitch.tv/widgets/live_embed_player.swf?channel=" + streamer);
    $("#flashvars").val("hostname=sv.twitch.tv&channel=" + streamer + "&auto_play=true&start_volume=0");

    $("#stream-list ul li").click(function(){
        $("#stream-list ul li.active").first().removeClass("active");
        $(this).addClass("active");
        var streamer = $(this).attr("id");
        $("#live_embed_player_flash").attr("data", "http://sv.twitch.tv/widgets/live_embed_player.swf?channel=" + streamer);
        $("#flashvars").val("hostname=sv.twitch.tv&channel=" + streamer + "&auto_play=true&start_volume=25");
    });
}); 

HTML:

<ul>
   <li class="active" id="name-of-stream"></li>
   <li></li>
   <li></li>
</ul>

 <div id="player">
<object type="application/x-shockwave-flash" height="480" width="720" id="live_embed_player_flash" data="" bgcolor="#000000">
        <param name="allowFullScreen" value="true" />
        <param name="allowScriptAccess" value="always" />
        <param name="allowNetworking" value="all" />
        <param name="movie" value="http://sv.twitch.tv/widgets/live_embed_player.swf" />
        <param name="flashvars" value="" />
    </object>
</div>

如果您想要示例链接,请点击此链接 (http://icguides.com/)!

4

1 回答 1

0

用 jQuery SWFobject 修复它

http://jquery.thewikies.com/swfobject/

将在此处发布代码以防有人发现此问题并需要答案。

<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/swfobject.jquery.js"></script>

    <script type="text/javascript" >
     $(function() { 
            var streamer = $("#stream-list ul li.active").first().attr("id");
            $('#player').flash({
                    swf: 'http://sv.twitch.tv/widgets/live_embed_player.swf?channel=' + streamer,
                    width: 720,
                    height: 480,
                    flashvars: {
                        hostname: 'sv.twitch.tv',
                        channel: streamer,
                        auto_play: 'true',
                        start_volume: '0'
                    }
                });

   

    $("#stream-list ul li").click(function(){
        $("#stream-list ul li.active").first().removeClass("active");
        $(this).addClass("active");
        var streamer = $(this).attr("id");
        $('#player').flash({
                swf: 'http://sv.twitch.tv/widgets/live_embed_player.swf?channel=' + streamer,
                width: 720,
                height: 480,
                    flashvars: {
                        channel: streamer,
                        start_volume: '25'
                    }
                });
    });
});     
</script>

所有需要的 HTML 是:

   <div id="stream-list">
       <ul>
           <li class="active" id="streamer-name"></li>
           <li></li>
       </ul>
   </div>

   <div id="player">

   </div>
于 2013-08-07T09:51:42.253 回答