继续操作前请注册或者登录。
胡斌

set rmtp url by recreate swf object,instead of reload web with different parameters

@@ -141,6 +141,8 @@ a:active { @@ -141,6 +141,8 @@ a:active {
141 var output; 141 var output;
142 var wsState = "idle"; 142 var wsState = "idle";
143 var websocket; 143 var websocket;
  144 + var initload = true;
  145 + var player;
144 146
145 function testWebSocket() 147 function testWebSocket()
146 { 148 {
@@ -180,7 +182,7 @@ a:active { @@ -180,7 +182,7 @@ a:active {
180 var byte_order = dv.getUint8(2, true); 182 var byte_order = dv.getUint8(2, true);
181 var data_len = dv.getUint32(4, true); 183 var data_len = dv.getUint32(4, true);
182 184
183 - if(result == 83){ 185 + if(result == 83){//get camera sucess
184 if(data_len > 4){ 186 if(data_len > 4){
185 var cam_num = dv.getUint32(8, true); 187 var cam_num = dv.getUint32(8, true);
186 var offset = 12; 188 var offset = 12;
@@ -201,7 +203,7 @@ a:active { @@ -201,7 +203,7 @@ a:active {
201 } 203 }
202 } 204 }
203 } 205 }
204 - else if(53 == result){ 206 + else if(53 == result){//get mic success
205 if(data_len > 4){ 207 if(data_len > 4){
206 var mic_num = dv.getUint32(8, true); 208 var mic_num = dv.getUint32(8, true);
207 var offset = 12; 209 var offset = 12;
@@ -221,6 +223,11 @@ a:active { @@ -221,6 +223,11 @@ a:active {
221 } 223 }
222 } 224 }
223 } 225 }
  226 + else if(85 == result){//cam_share success
  227 + document.getElementById('inputURL').value = "rtmp://127.0.0.1/live/cs";
  228 + queryParameters['source'] = "rtmp://127.0.0.1/live/cs";
  229 + initialise();
  230 + }
224 else{ 231 else{
225 var data_sting = new TextDecoder("utf-8").decode(data); 232 var data_sting = new TextDecoder("utf-8").decode(data);
226 writeToScreen('<span style="color: blue;">RESPONSE: ' + data_sting + ' </span>'); 233 writeToScreen('<span style="color: blue;">RESPONSE: ' + data_sting + ' </span>');
@@ -289,8 +296,8 @@ a:active { @@ -289,8 +296,8 @@ a:active {
289 var buffer = new ArrayBuffer(cmd.data_len); 296 var buffer = new ArrayBuffer(cmd.data_len);
290 var mic_name_len = new Uint32Array(buffer, 0, 1); 297 var mic_name_len = new Uint32Array(buffer, 0, 1);
291 var micSel = document.getElementById("mics"); 298 var micSel = document.getElementById("mics");
292 - var index = micSel.selectedIndex; // 选中索引  
293 - var sel_mic_name = micSel.options[index].text; // 选中文本 299 + var index = micSel.selectedIndex;
  300 + var sel_mic_name = micSel.options[index].text;
294 mic_name_len[0] = sel_mic_name.length; 301 mic_name_len[0] = sel_mic_name.length;
295 var urlname_len = new Uint32Array(buffer, 4, 1); 302 var urlname_len = new Uint32Array(buffer, 4, 1);
296 urlname_len[0] = 0; 303 urlname_len[0] = 0;
@@ -316,8 +323,8 @@ a:active { @@ -316,8 +323,8 @@ a:active {
316 var buffer = new ArrayBuffer(cmd.data_len); 323 var buffer = new ArrayBuffer(cmd.data_len);
317 var cam_name_len = new Uint32Array(buffer, 0, 1); 324 var cam_name_len = new Uint32Array(buffer, 0, 1);
318 var camSel = document.getElementById("cameras"); 325 var camSel = document.getElementById("cameras");
319 - var index = camSel.selectedIndex; // 选中索引  
320 - var sel_cam_name = camSel.options[index].text; // 选中文本 326 + var index = camSel.selectedIndex;
  327 + var sel_cam_name = camSel.options[index].text;
321 cam_name_len[0] = sel_cam_name.length; 328 cam_name_len[0] = sel_cam_name.length;
322 var urlname_len = new Uint32Array(buffer, 4, 1); 329 var urlname_len = new Uint32Array(buffer, 4, 1);
323 urlname_len[0] = 0; 330 urlname_len[0] = 0;
@@ -372,6 +379,10 @@ a:active { @@ -372,6 +379,10 @@ a:active {
372 379
373 } 380 }
374 381
  382 + function onJavaScriptBridgeCreated(id){
  383 + player = document.getElementById(id);
  384 + }
  385 +
375 function initialise() 386 function initialise()
376 { 387 {
377 function getUrlParam( name ) 388 function getUrlParam( name )
@@ -386,9 +397,23 @@ a:active { @@ -386,9 +397,23 @@ a:active {
386 return unescape( results[1] ); 397 return unescape( results[1] );
387 } 398 }
388 399
  400 + if(initload == true){
389 queryParameters['source'] = getUrlParam('source'); 401 queryParameters['source'] = getUrlParam('source');
390 queryParameters['type'] = getUrlParam('type'); 402 queryParameters['type'] = getUrlParam('type');
391 queryParameters['idx'] = getUrlParam('idx'); 403 queryParameters['idx'] = getUrlParam('idx');
  404 + initload = false;
  405 + }
  406 + else{
  407 + flashVars = "";
  408 + swfobject.removeSWF("StrobeMediaPlayback");
  409 + var v = document.getElementById("flashContent");
  410 + if(v == null){
  411 + var flashContentParent = document.getElementById("flashContentParent");
  412 + if(flashContentParent){
  413 + flashContentParent.innerHTML = "<div id=\"flashContent\"></div>";
  414 + }
  415 + }
  416 + }
392 417
393 if( queryParameters['source'] == "" ) 418 if( queryParameters['source'] == "" )
394 queryParameters['source'] = "rtmp://localhost/live/ss"; 419 queryParameters['source'] = "rtmp://localhost/live/ss";
@@ -399,6 +424,7 @@ a:active { @@ -399,6 +424,7 @@ a:active {
399 if( queryParameters['idx'] == "" ) 424 if( queryParameters['idx'] == "" )
400 queryParameters['idx'] = "2"; 425 queryParameters['idx'] = "2";
401 426
  427 +
402 flashVars += "&src="; 428 flashVars += "&src=";
403 flashVars += queryParameters['source']; 429 flashVars += queryParameters['source'];
404 430
@@ -419,7 +445,8 @@ a:active { @@ -419,7 +445,8 @@ a:active {
419 streamType: queryParameters['type'], 445 streamType: queryParameters['type'],
420 autoPlay: "true", 446 autoPlay: "true",
421 controlBarAutoHide: "true", 447 controlBarAutoHide: "true",
422 - controlBarPosition: "bottom" 448 + controlBarPosition: "bottom",
  449 + javascriptCallbackFunction: "onJavaScriptBridgeCreated"
423 }; 450 };
424 451
425 tag = "&lt;object width='640' height='377' id='StrobeMediaPlayback' name='StrobeMediaPlayback' type='application/x-shockwave-flash' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' &gt;&lt;param name='movie' value='swfs/StrobeMediaPlayback.swf' /&gt; &lt;param name='quality' value='high' /&gt; &lt;param name='bgcolor' value='#000000' /&gt; &lt;param name='allowfullscreen' value='true' /&gt; &lt;param name='flashvars' value= '"+ 452 tag = "&lt;object width='640' height='377' id='StrobeMediaPlayback' name='StrobeMediaPlayback' type='application/x-shockwave-flash' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' &gt;&lt;param name='movie' value='swfs/StrobeMediaPlayback.swf' /&gt; &lt;param name='quality' value='high' /&gt; &lt;param name='bgcolor' value='#000000' /&gt; &lt;param name='allowfullscreen' value='true' /&gt; &lt;param name='flashvars' value= '"+
@@ -440,23 +467,15 @@ a:active { @@ -440,23 +467,15 @@ a:active {
440 attributes.align = "middle"; 467 attributes.align = "middle";
441 swfobject.embedSWF("swfs/StrobeMediaPlayback.swf", "flashContent", "640", "377", swfVersionStr, xiSwfUrlStr, soFlashVars, params, attributes); 468 swfobject.embedSWF("swfs/StrobeMediaPlayback.swf", "flashContent", "640", "377", swfVersionStr, xiSwfUrlStr, soFlashVars, params, attributes);
442 <!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. --> 469 <!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
  470 + if(initload == true){
443 swfobject.createCSS("#flashContent", "display:block;text-align:left;"); 471 swfobject.createCSS("#flashContent", "display:block;text-align:left;");
444 } 472 }
  473 + }
445 474
446 function playStream() 475 function playStream()
447 { 476 {
448 - var url = "source=" + document.getElementById('inputURL').value;  
449 - var type;  
450 -  
451 - if(document.getElementById('vodCheckbox').checked==true)  
452 - type="vod";  
453 - else  
454 - type="live";  
455 -  
456 - url += ("&type=" + type);  
457 -  
458 - document.getElementById('playBtn').href="demo.html?" + url;  
459 - 477 + queryParameters['source'] = document.getElementById('inputURL').value;
  478 + initialise();
460 } 479 }
461 480
462 function checkbox(type) 481 function checkbox(type)
@@ -548,7 +567,7 @@ a:active { @@ -548,7 +567,7 @@ a:active {
548 JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show 567 JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
549 when JavaScript is disabled. 568 when JavaScript is disabled.
550 --> 569 -->
551 - 570 + <div id="flashContentParent">
552 <div id="flashContent"> 571 <div id="flashContent">
553 <p>To view this page ensure that Adobe Flash Player version 10.3.0 or greater is installed.</p> 572 <p>To view this page ensure that Adobe Flash Player version 10.3.0 or greater is installed.</p>
554 <script type="text/javascript"> 573 <script type="text/javascript">
@@ -557,6 +576,7 @@ a:active { @@ -557,6 +576,7 @@ a:active {
557 + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" ); 576 + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
558 </script> 577 </script>
559 </div> 578 </div>
  579 + </div>
560 <noscript> 580 <noscript>
561 <a href="http://www.adobe.com/go/getflashplayer/" style="color:black"><img src="images/ERROR_getFlashPlayer.gif" width="640" height="377" /></a> 581 <a href="http://www.adobe.com/go/getflashplayer/" style="color:black"><img src="images/ERROR_getFlashPlayer.gif" width="640" height="377" /></a>
562 582
@@ -30,6 +30,7 @@ var swfobject = function() { @@ -30,6 +30,7 @@ var swfobject = function() {
30 dynamicStylesheet, 30 dynamicStylesheet,
31 dynamicStylesheetMedia, 31 dynamicStylesheetMedia,
32 autoHideShow = true, 32 autoHideShow = true,
  33 + needRebuild = false,
33 34
34 /* Centralized function for browser feature detection 35 /* Centralized function for browser feature detection
35 - User agent string detection is only used when no good alternative is possible 36 - User agent string detection is only used when no good alternative is possible
@@ -137,6 +138,11 @@ var swfobject = function() { @@ -137,6 +138,11 @@ var swfobject = function() {
137 } 138 }
138 139
139 function addDomLoadEvent(fn) { 140 function addDomLoadEvent(fn) {
  141 + if(needRebuild){
  142 + isDomLoaded = false;
  143 + fn();
  144 + return;
  145 + }
140 if (isDomLoaded) { 146 if (isDomLoaded) {
141 fn(); 147 fn();
142 } 148 }
@@ -474,6 +480,7 @@ var swfobject = function() { @@ -474,6 +480,7 @@ var swfobject = function() {
474 function removeSWF(id) { 480 function removeSWF(id) {
475 var obj = getElementById(id); 481 var obj = getElementById(id);
476 if (obj && obj.nodeName == "OBJECT") { 482 if (obj && obj.nodeName == "OBJECT") {
  483 + needRebuild = true;
477 if (ua.ie && ua.win) { 484 if (ua.ie && ua.win) {
478 obj.style.display = "none"; 485 obj.style.display = "none";
479 (function(){ 486 (function(){