0

そこで、Twitch ストリームを Web サイトに統合することを計画しています。それぞれを埋め込むのは非常に簡単ですが、全員の帯域幅でより簡単だと感じたのは、Javascript を記述して 1 つのストリームを表示し、ボタンを押して属性値を交換して他のユーザーの Twitch アカウント名と一致させることです。これまでのところ、私が思いついたことはうまくいかなかったので、今日ここにいます。

これは、HTML についてこれまでに思いついたものです。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Site - Build 1.1.6.5 - Videos Page</title>
<link rel="stylesheet" type="text/css" href="main.css" />
<script src="scripts/stream-switch.js"></script>
</head>
<body>
<object type="application/x-shockwave-flash" height="540" width="960" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=username1" bgcolor="#000000"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" /><param id="flashvars" name="flashvars" value="hostname=www.twitch.tv&channel=username1&auto_play=true&start_volume=25" /></object>
<br/>
<button type="button" onclick="User1Stream();">User1's Stream</button>
<button type="button" onclick="User2Stream();">User2's Stream</button>
</body>
</html>

埋め込まれた JS は次のとおりです。

function User2Stream()
{
   var StreamObject = document.getElementById("live_embed_player_flash");
   var StreamParameter = document.getElementById("flashvars");
   if (StreamObject != null)
   {
       StreamObject.setAttribute('data', 'http://www.twitch.tv/widgets/live_embed_player.swf?channel=username2');
       StreamParameter = setAttribute('value', 'hostname=www.twitch.tv&channel=username2&auto_play=true&start_volume=25');
   }
}
function User1Stream()
{
   var StreamObject = document.getElementById("live_embed_player_flash");
   var StreamParameter = document.getElementById("flashvars");
   if (StreamObject != null)
   {
       StreamObject.setAttribute('data', 'http://www.twitch.tv/widgets/live_embed_player.swf?channel=username1');
       StreamParameter = setAttribute('value', 'hostname=www.twitch.tv&channel=username1&auto_play=true&start_volume=25');
   }
}

さて、私がここで間違っていると思うことを教えてください。うまくいけば、それはあまりにも間違っていません。

4

1 に答える 1

0

setAttribute(この行の後に 2 つの一重引用符がありますfunction User2Stream()

StreamParameter = setAttribute(''value', 'hostname=www.twitch.tv&channel=username2&auto_play=true&start_volume=25');

これにより、Javascript コンソールで未終了の文字列エラーが発生するはずです。の終わりに向かってエラーをもう一度繰り返しますfunction User1Stream()

StreamParameter = setAttribute(''value', 'hostname=www.twitch.tv&channel=username1&auto_play=true&start_volume=25');

編集

このためにjsFiddleを作成しました。上記のsetAttributeはStreamObject.setAttributeであるべきだと思います

StreamObject.setAttribute('value', 'hostname=www.twitch.tv&channel=username1&auto_play=true&start_volume=25');
于 2014-06-05T21:06:19.003 に答える