winlin

for #5114, display metadata.

@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 * depends: jquery1.10 5 * depends: jquery1.10
6 * https://code.csdn.net/snippets/147103 6 * https://code.csdn.net/snippets/147103
7 * @see: http://blog.csdn.net/win_lin/article/details/17994347 7 * @see: http://blog.csdn.net/win_lin/article/details/17994347
8 - * v 1.0.11 8 + * v 1.0.14
9 */ 9 */
10 10
11 /** 11 /**
@@ -96,19 +96,76 @@ function system_array_get(arr, elem_or_function) { @@ -96,19 +96,76 @@ function system_array_get(arr, elem_or_function) {
96 /** 96 /**
97 * to iterate on array. 97 * to iterate on array.
98 * @param arr the array to iterate on. 98 * @param arr the array to iterate on.
99 - * @param pfn the function to apply on it 99 + * @param pfn the function to apply on it. return false to break loop.
100 * for example, 100 * for example,
101 * arr = [10, 15, 20, 30, 20, 40] 101 * arr = [10, 15, 20, 30, 20, 40]
102 * system_array_foreach(arr, function(elem, index){ 102 * system_array_foreach(arr, function(elem, index){
103 * console.log('index=' + index + ',elem=' + elem); 103 * console.log('index=' + index + ',elem=' + elem);
104 * }); 104 * });
  105 + * @return true when iterate all elems.
105 */ 106 */
106 function system_array_foreach(arr, pfn) { 107 function system_array_foreach(arr, pfn) {
  108 + if (!pfn) {
  109 + return false;
  110 + }
  111 +
107 for (var i = 0; i < arr.length; i++) { 112 for (var i = 0; i < arr.length; i++) {
108 - if (pfn) {  
109 - pfn(arr[i], i) 113 + if (!pfn(arr[i], i)) {
  114 + return false;
  115 + }
  116 + }
  117 +
  118 + return true;
  119 +}
  120 +
  121 +/**
  122 + * whether the str starts with flag.
  123 + */
  124 +function system_string_startswith(str, flag) {
  125 + if (typeof flag == "object" && flag.constructor == Array) {
  126 + for (var i = 0; i < flag.length; i++) {
  127 + if (system_string_startswith(str, flag[i])) {
  128 + return true;
  129 + }
110 } 130 }
111 } 131 }
  132 +
  133 + return str && flag && str.length >= flag.length && str.indexOf(flag) == 0;
  134 +}
  135 +
  136 +/**
  137 + * whether the str ends with flag.
  138 + */
  139 +function system_string_endswith(str, flag) {
  140 + if (typeof flag == "object" && flag.constructor == Array) {
  141 + for (var i = 0; i < flag.length; i++) {
  142 + if (system_string_endswith(str, flag[i])) {
  143 + return true;
  144 + }
  145 + }
  146 + }
  147 +
  148 + return str && flag && str.length >= flag.length && str.indexOf(flag) == str.length - flag.length;
  149 +}
  150 +
  151 +/**
  152 + * trim the start and end of flag in str.
  153 + * @param flag a string to trim.
  154 + */
  155 +function system_string_trim(str, flag) {
  156 + if (!flag || !flag.length || typeof flag != "string") {
  157 + return str;
  158 + }
  159 +
  160 + while (system_string_startswith(str, flag)) {
  161 + str = str.substr(flag.length);
  162 + }
  163 +
  164 + while (system_string_endswith(str, flag)) {
  165 + str = str.substr(0, str.length - flag.length);
  166 + }
  167 +
  168 + return str;
112 } 169 }
113 170
114 /** 171 /**
@@ -186,12 +243,19 @@ function parse_query_string(){ @@ -186,12 +243,19 @@ function parse_query_string(){
186 } 243 }
187 } 244 }
188 245
  246 + // split again for angularjs.
  247 + if (query_string.indexOf("?") > 0) {
  248 + query_string = query_string.split("?")[1];
  249 + }
  250 +
189 var queries = query_string.split("&"); 251 var queries = query_string.split("&");
190 - $(queries).each(function(){  
191 - var query = this.split("="); 252 + for (var i = 0; i < queries.length; i++) {
  253 + var elem = queries[i];
  254 +
  255 + var query = elem.split("=");
192 obj[query[0]] = query[1]; 256 obj[query[0]] = query[1];
193 obj.user_query[query[0]] = query[1]; 257 obj.user_query[query[0]] = query[1];
194 - }); 258 + }
195 259
196 return obj; 260 return obj;
197 } 261 }
@@ -244,6 +308,8 @@ function parse_rtmp_url(rtmp_url) { @@ -244,6 +308,8 @@ function parse_rtmp_url(rtmp_url) {
244 } 308 }
245 309
246 var ret = { 310 var ret = {
  311 + url: rtmp_url,
  312 + schema: a.protocol.replace(":", ""),
247 server: a.hostname, port: port, 313 server: a.hostname, port: port,
248 vhost: vhost, app: app, stream: stream 314 vhost: vhost, app: app, stream: stream
249 }; 315 };
@@ -500,7 +566,14 @@ AsyncRefresh2.prototype.initialize = function(pfn, timeout) { @@ -500,7 +566,14 @@ AsyncRefresh2.prototype.initialize = function(pfn, timeout) {
500 * stop refresh, the refresh pfn is set to null. 566 * stop refresh, the refresh pfn is set to null.
501 */ 567 */
502 AsyncRefresh2.prototype.stop = function() { 568 AsyncRefresh2.prototype.stop = function() {
503 - this.refresh_change(null, null); 569 + this.__call.__enabled = false;
  570 +}
  571 +/**
  572 + * restart refresh, use previous config.
  573 + */
  574 +AsyncRefresh2.prototype.restart = function() {
  575 + this.__call.__enabled = true;
  576 + this.request(0);
504 } 577 }
505 /** 578 /**
506 * change refresh pfn, the old pfn will set to disabled. 579 * change refresh pfn, the old pfn will set to disabled.
@@ -568,4 +641,4 @@ AsyncRefresh2.prototype.request = function(timeout) { @@ -568,4 +641,4 @@ AsyncRefresh2.prototype.request = function(timeout) {
568 * depends: jquery1.10, boostrap2 641 * depends: jquery1.10, boostrap2
569 * https://code.csdn.net/snippets/146160 642 * https://code.csdn.net/snippets/146160
570 * @see: http://blog.csdn.net/win_lin/article/details/17628631 643 * @see: http://blog.csdn.net/win_lin/article/details/17628631
571 - */ 644 + */
@@ -24,6 +24,20 @@ @@ -24,6 +24,20 @@
24 <script type="text/javascript" src="js/jwplayer.js" ></script> 24 <script type="text/javascript" src="js/jwplayer.js" ></script>
25 <script type='text/javascript'>jwplayer.key = 'N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ=='; </script> 25 <script type='text/javascript'>jwplayer.key = 'N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ=='; </script>
26 <script type="text/javascript"> 26 <script type="text/javascript">
  27 + /****
  28 + * The parameters for this page:
  29 + * schema, the protocol schema, rtmp or http.
  30 + * server, the ip of the url.
  31 + * port, the rtmp port of url.
  32 + * vhost, the vhost of url, can equals to server.
  33 + * app, the app of url.
  34 + * stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
  35 + * autostart, whether auto play the stream.
  36 + * Additional params:
  37 + * hls_vhost, the vhost for hls.
  38 + * hls_port, the port for hls play.
  39 + * hls_autostart, whether auto play the hls stream.
  40 + */
27 var _player = null; 41 var _player = null;
28 var _url = null; 42 var _url = null;
29 $(function(){ 43 $(function(){
@@ -384,6 +384,9 @@ @@ -384,6 +384,9 @@
384 <input class="span2" style="width:135px" id="player_clock" type="text" placeholder="年-月-日 时:分:秒"> 384 <input class="span2" style="width:135px" id="player_clock" type="text" placeholder="年-月-日 时:分:秒">
385 </div> 385 </div>
386 </div> 386 </div>
  387 + <div>
  388 + <span id="debug_info"></span>
  389 + </div>
387 </div> 390 </div>
388 </div> 391 </div>
389 <footer> 392 <footer>
@@ -466,6 +469,19 @@ @@ -466,6 +469,19 @@
466 __active_mbt.addClass("active"); 469 __active_mbt.addClass("active");
467 } 470 }
468 471
  472 + /****
  473 + * The parameters for this page:
  474 + * schema, the protocol schema, rtmp or http.
  475 + * server, the ip of the url.
  476 + * port, the rtmp port of url.
  477 + * vhost, the vhost of url, can equals to server.
  478 + * app, the app of url.
  479 + * stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
  480 + * autostart, whether auto play the stream.
  481 + * for example:
  482 + * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream&server=ossrs.net&port=1935&autostart=true&schema=rtmp
  483 + * http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream.flv&server=ossrs.net&port=8080&autostart=true&schema=http
  484 + */
469 $(function(){ 485 $(function(){
470 var query = parse_query_string(); 486 var query = parse_query_string();
471 487
@@ -496,6 +512,9 @@ @@ -496,6 +512,9 @@
496 }; 512 };
497 srs_player.on_player_metadata = function(metadata) { 513 srs_player.on_player_metadata = function(metadata) {
498 $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")"); 514 $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")");
  515 + if (metadata.ip && metadata.pid && metadata.cid) {
  516 + $("#debug_info").text("DEBUG: " + metadata.ip + ' grep -in "\\[' + metadata.pid + '\\]\\[' + metadata.cid + '\\]"');
  517 + }
499 select_dar("#btn_dar_original", 0, 0); 518 select_dar("#btn_dar_original", 0, 0);
500 select_fs_size("#btn_fs_size_screen_100", "screen", 100); 519 select_fs_size("#btn_fs_size_screen_100", "screen", 100);
501 }; 520 };
@@ -551,6 +570,9 @@ @@ -551,6 +570,9 @@
551 + "vhost=" + rtmp.vhost + "&app=" + rtmp.app + "&stream=" + rtmp.stream 570 + "vhost=" + rtmp.vhost + "&app=" + rtmp.app + "&stream=" + rtmp.stream
552 + "&server=" + rtmp.server + "&port=" + rtmp.port 571 + "&server=" + rtmp.server + "&port=" + rtmp.port
553 + "&autostart=true"; 572 + "&autostart=true";
  573 + if (rtmp.schema == "http") {
  574 + url += "&schema=http";
  575 + }
554 $("#player_url").text($("#txt_url").val()).attr("href", url); 576 $("#player_url").text($("#txt_url").val()).attr("href", url);
555 577
556 $("#link_server").text(rtmp.server); 578 $("#link_server").text(rtmp.server);
@@ -39,3 +39,4 @@ @@ -39,3 +39,4 @@
39 <flashCatalyst validateFlashCatalystCompatibility="false"/> 39 <flashCatalyst validateFlashCatalystCompatibility="false"/>
40 </actionScriptProperties> 40 </actionScriptProperties>
41 41
  42 +
@@ -32,8 +32,8 @@ package @@ -32,8 +32,8 @@ package
32 private var js_on_player_metadata:String = null; 32 private var js_on_player_metadata:String = null;
33 private var js_on_player_timer:String = null; 33 private var js_on_player_timer:String = null;
34 private var js_on_player_empty:String = null; 34 private var js_on_player_empty:String = null;
35 - private var js_on_player_full:String = null;  
36 - 35 + private var js_on_player_full:String = null;
  36 +
37 // play param url. 37 // play param url.
38 private var user_url:String = null; 38 private var user_url:String = null;
39 // play param, user set width and height 39 // play param, user set width and height
@@ -98,8 +98,8 @@ package @@ -98,8 +98,8 @@ package
98 this.js_on_player_ready = flashvars.on_player_ready; 98 this.js_on_player_ready = flashvars.on_player_ready;
99 this.js_on_player_metadata = flashvars.on_player_metadata; 99 this.js_on_player_metadata = flashvars.on_player_metadata;
100 this.js_on_player_timer = flashvars.on_player_timer; 100 this.js_on_player_timer = flashvars.on_player_timer;
101 - this.js_on_player_empty = flashvars.on_player_empty;  
102 - this.js_on_player_full = flashvars.on_player_full; 101 + this.js_on_player_empty = flashvars.on_player_empty;
  102 + this.js_on_player_full = flashvars.on_player_full;
103 103
104 this.media_timer.addEventListener(TimerEvent.TIMER, this.system_on_timer); 104 this.media_timer.addEventListener(TimerEvent.TIMER, this.system_on_timer);
105 this.media_timer.start(); 105 this.media_timer.start();
@@ -121,11 +121,11 @@ package @@ -121,11 +121,11 @@ package
121 flash.external.ExternalInterface.addCallback("__play", this.js_call_play); 121 flash.external.ExternalInterface.addCallback("__play", this.js_call_play);
122 flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop); 122 flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop);
123 flash.external.ExternalInterface.addCallback("__pause", this.js_call_pause); 123 flash.external.ExternalInterface.addCallback("__pause", this.js_call_pause);
124 - flash.external.ExternalInterface.addCallback("__resume", this.js_call_resume); 124 + flash.external.ExternalInterface.addCallback("__resume", this.js_call_resume);
125 flash.external.ExternalInterface.addCallback("__set_dar", this.js_call_set_dar); 125 flash.external.ExternalInterface.addCallback("__set_dar", this.js_call_set_dar);
126 flash.external.ExternalInterface.addCallback("__set_fs", this.js_call_set_fs_size); 126 flash.external.ExternalInterface.addCallback("__set_fs", this.js_call_set_fs_size);
127 flash.external.ExternalInterface.addCallback("__set_bt", this.js_call_set_bt); 127 flash.external.ExternalInterface.addCallback("__set_bt", this.js_call_set_bt);
128 - flash.external.ExternalInterface.addCallback("__set_mbt", this.js_call_set_mbt); 128 + flash.external.ExternalInterface.addCallback("__set_mbt", this.js_call_set_mbt);
129 129
130 flash.external.ExternalInterface.call(this.js_on_player_ready, this.js_id); 130 flash.external.ExternalInterface.call(this.js_on_player_ready, this.js_id);
131 } 131 }
@@ -134,39 +134,39 @@ package @@ -134,39 +134,39 @@ package
134 * system callack event, timer to do some regular tasks. 134 * system callack event, timer to do some regular tasks.
135 */ 135 */
136 private function system_on_timer(evt:TimerEvent):void { 136 private function system_on_timer(evt:TimerEvent):void {
137 - var ms:NetStream = this.media_stream;  
138 - 137 + var ms:NetStream = this.media_stream;
  138 +
139 if (!ms) { 139 if (!ms) {
140 //log("stream is null, ignore timer event."); 140 //log("stream is null, ignore timer event.");
141 return; 141 return;
142 } 142 }
143 -  
144 - var rtime:Number = flash.utils.getTimer();  
145 - var bitrate:Number = Number((ms.info.videoBytesPerSecond + ms.info.audioBytesPerSecond) * 8 / 1000); 143 +
  144 + var rtime:Number = flash.utils.getTimer();
  145 + var bitrate:Number = Number((ms.info.videoBytesPerSecond + ms.info.audioBytesPerSecond) * 8 / 1000);
146 log("on timer, time=" + ms.time.toFixed(2) + "s, buffer=" + ms.bufferLength.toFixed(2) + "s" 146 log("on timer, time=" + ms.time.toFixed(2) + "s, buffer=" + ms.bufferLength.toFixed(2) + "s"
147 - + ", bitrate=" + bitrate.toFixed(1) + "kbps"  
148 - + ", fps=" + ms.currentFPS.toFixed(1)  
149 - + ", rtime=" + rtime.toFixed(0)  
150 - ); 147 + + ", bitrate=" + bitrate.toFixed(1) + "kbps"
  148 + + ", fps=" + ms.currentFPS.toFixed(1)
  149 + + ", rtime=" + rtime.toFixed(0)
  150 + );
151 flash.external.ExternalInterface.call( 151 flash.external.ExternalInterface.call(
152 this.js_on_player_timer, this.js_id, ms.time, ms.bufferLength, 152 this.js_on_player_timer, this.js_id, ms.time, ms.bufferLength,
153 - bitrate, ms.currentFPS, rtime  
154 - ); 153 + bitrate, ms.currentFPS, rtime
  154 + );
  155 + }
  156 +
  157 + /**
  158 + * system callback event, when stream is empty.
  159 + */
  160 + private function system_on_buffer_empty():void {
  161 + var time:Number = flash.utils.getTimer();
  162 + log("stream is empty at " + time + "ms");
  163 + flash.external.ExternalInterface.call(this.js_on_player_empty, this.js_id, time);
  164 + }
  165 + private function system_on_buffer_full():void {
  166 + var time:Number = flash.utils.getTimer();
  167 + log("stream is full at " + time + "ms");
  168 + flash.external.ExternalInterface.call(this.js_on_player_full, this.js_id, time);
155 } 169 }
156 -  
157 - /**  
158 - * system callback event, when stream is empty.  
159 - */  
160 - private function system_on_buffer_empty():void {  
161 - var time:Number = flash.utils.getTimer();  
162 - log("stream is empty at " + time + "ms");  
163 - flash.external.ExternalInterface.call(this.js_on_player_empty, this.js_id, time);  
164 - }  
165 - private function system_on_buffer_full():void {  
166 - var time:Number = flash.utils.getTimer();  
167 - log("stream is full at " + time + "ms");  
168 - flash.external.ExternalInterface.call(this.js_on_player_full, this.js_id, time);  
169 - }  
170 170
171 /** 171 /**
172 * system callack event, when got metadata from stream. 172 * system callack event, when got metadata from stream.
@@ -175,6 +175,11 @@ package @@ -175,6 +175,11 @@ package
175 private function system_on_metadata(metadata:Object):void { 175 private function system_on_metadata(metadata:Object):void {
176 this.media_metadata = metadata; 176 this.media_metadata = metadata;
177 177
  178 + // update the debug info.
  179 + if (metadata) {
  180 + on_debug_info(metadata);
  181 + }
  182 +
178 // for js. 183 // for js.
179 var obj:Object = __get_video_size_object(); 184 var obj:Object = __get_video_size_object();
180 185
@@ -190,6 +195,21 @@ package @@ -190,6 +195,21 @@ package
190 if (srs_authors != null) { 195 if (srs_authors != null) {
191 obj.contributor = srs_authors; 196 obj.contributor = srs_authors;
192 } 197 }
  198 + if (srs_id != null) {
  199 + obj.cid = srs_id;
  200 + }
  201 + if (srs_pid != null) {
  202 + obj.pid = srs_pid;
  203 + }
  204 + if (srs_server_ip != null) {
  205 + obj.ip = srs_server_ip;
  206 + }
  207 +
  208 + var s:String = "";
  209 + for (var key:String in obj) {
  210 + s += key + "=" + obj[key] + " ";
  211 + }
  212 + log("metadata is " + s);
193 213
194 var code:int = flash.external.ExternalInterface.call(js_on_player_metadata, js_id, obj); 214 var code:int = flash.external.ExternalInterface.call(js_on_player_metadata, js_id, obj);
195 if (code != 0) { 215 if (code != 0) {
@@ -231,7 +251,7 @@ package @@ -231,7 +251,7 @@ package
231 private function js_call_pause():void { 251 private function js_call_pause():void {
232 if (this.media_stream) { 252 if (this.media_stream) {
233 this.media_stream.pause(); 253 this.media_stream.pause();
234 - log("user pause play"); 254 + log("user pause play");
235 } 255 }
236 } 256 }
237 257
@@ -241,7 +261,7 @@ package @@ -241,7 +261,7 @@ package
241 private function js_call_resume():void { 261 private function js_call_resume():void {
242 if (this.media_stream) { 262 if (this.media_stream) {
243 this.media_stream.resume(); 263 this.media_stream.resume();
244 - log("user resume play"); 264 + log("user resume play");
245 } 265 }
246 } 266 }
247 267
@@ -259,7 +279,7 @@ package @@ -259,7 +279,7 @@ package
259 user_dar_den = den; 279 user_dar_den = den;
260 280
261 flash.utils.setTimeout(__execute_user_set_dar, 0); 281 flash.utils.setTimeout(__execute_user_set_dar, 0);
262 - log("user set dar to " + num + "/" + den); 282 + log("user set dar to " + num + "/" + den);
263 } 283 }
264 284
265 /** 285 /**
@@ -273,7 +293,7 @@ package @@ -273,7 +293,7 @@ package
273 private function js_call_set_fs_size(refer:String, percent:int):void { 293 private function js_call_set_fs_size(refer:String, percent:int):void {
274 user_fs_refer = refer; 294 user_fs_refer = refer;
275 user_fs_percent = percent; 295 user_fs_percent = percent;
276 - log("user set refer to " + refer + ", percent to" + percent); 296 + log("user set refer to " + refer + ", percent to" + percent);
277 } 297 }
278 298
279 /** 299 /**
@@ -283,21 +303,21 @@ package @@ -283,21 +303,21 @@ package
283 private function js_call_set_bt(buffer_time:Number):void { 303 private function js_call_set_bt(buffer_time:Number):void {
284 if (this.media_stream) { 304 if (this.media_stream) {
285 this.media_stream.bufferTime = buffer_time; 305 this.media_stream.bufferTime = buffer_time;
286 - log("user set bufferTime to " + buffer_time.toFixed(2) + "s"); 306 + log("user set bufferTime to " + buffer_time.toFixed(2) + "s");
  307 + }
  308 + }
  309 +
  310 + /**
  311 + * set the max stream buffer time in seconds.
  312 + * @max_buffer_time the max buffer time in seconds.
  313 + * @remark this is the key feature for realtime communication by flash.
  314 + */
  315 + private function js_call_set_mbt(max_buffer_time:Number):void {
  316 + if (this.media_stream) {
  317 + this.media_stream.bufferTimeMax = max_buffer_time;
  318 + log("user set bufferTimeMax to " + max_buffer_time.toFixed(2) + "s");
287 } 319 }
288 } 320 }
289 -  
290 - /**  
291 - * set the max stream buffer time in seconds.  
292 - * @max_buffer_time the max buffer time in seconds.  
293 - * @remark this is the key feature for realtime communication by flash.  
294 - */  
295 - private function js_call_set_mbt(max_buffer_time:Number):void {  
296 - if (this.media_stream) {  
297 - this.media_stream.bufferTimeMax = max_buffer_time;  
298 - log("user set bufferTimeMax to " + max_buffer_time.toFixed(2) + "s");  
299 - }  
300 - }  
301 321
302 /** 322 /**
303 * function for js to call: to stop the stream. ignore if not play. 323 * function for js to call: to stop the stream. ignore if not play.
@@ -315,7 +335,7 @@ package @@ -315,7 +335,7 @@ package
315 this.media_conn.close(); 335 this.media_conn.close();
316 this.media_conn = null; 336 this.media_conn = null;
317 } 337 }
318 - log("player stopped"); 338 + log("player stopped");
319 } 339 }
320 340
321 // srs infos 341 // srs infos
@@ -350,12 +370,36 @@ package @@ -350,12 +370,36 @@ package
350 } 370 }
351 371
352 /** 372 /**
  373 + * server can set the debug info in _result of RTMP connect, or metadata.
  374 + */
  375 + private function on_debug_info(data:*):void {
  376 + if (data.hasOwnProperty("srs_server")) {
  377 + srs_server = data.srs_server;
  378 + }
  379 + if (data.hasOwnProperty("srs_primary")) {
  380 + srs_primary = data.srs_primary;
  381 + }
  382 + if (data.hasOwnProperty("srs_authors")) {
  383 + srs_authors = data.srs_authors;
  384 + }
  385 + if (data.hasOwnProperty("srs_id")) {
  386 + srs_id = data.srs_id;
  387 + }
  388 + if (data.hasOwnProperty("srs_pid")) {
  389 + srs_pid = data.srs_pid;
  390 + }
  391 + if (data.hasOwnProperty("srs_server_ip")) {
  392 + srs_server_ip = data.srs_server_ip;
  393 + }
  394 + }
  395 +
  396 + /**
353 * function for js to call: to play the stream. stop then play. 397 * function for js to call: to play the stream. stop then play.
354 * @param url, the rtmp/http url to play. 398 * @param url, the rtmp/http url to play.
355 * @param _width, the player width. 399 * @param _width, the player width.
356 * @param _height, the player height. 400 * @param _height, the player height.
357 * @param buffer_time, the buffer time in seconds. recommend to >=0.5 401 * @param buffer_time, the buffer time in seconds. recommend to >=0.5
358 - * @param max_buffer_time, the max buffer time in seconds. recommend to 3 x buffer_time. 402 + * @param max_buffer_time, the max buffer time in seconds. recommend to 3 x buffer_time.
359 * @param volume, the volume, 0 is mute, 1 is 100%, 2 is 200%. 403 * @param volume, the volume, 0 is mute, 1 is 100%, 2 is 200%.
360 */ 404 */
361 private function js_call_play(url:String, _width:int, _height:int, buffer_time:Number, max_buffer_time:Number, volume:Number):void { 405 private function js_call_play(url:String, _width:int, _height:int, buffer_time:Number, max_buffer_time:Number, volume:Number):void {
@@ -363,8 +407,8 @@ package @@ -363,8 +407,8 @@ package
363 this.user_w = _width; 407 this.user_w = _width;
364 this.user_h = _height; 408 this.user_h = _height;
365 log("start to play url: " + this.user_url + ", w=" + this.user_w + ", h=" + this.user_h 409 log("start to play url: " + this.user_url + ", w=" + this.user_w + ", h=" + this.user_h
366 - + ", buffer=" + buffer_time.toFixed(2) + "s, max_buffer=" + max_buffer_time.toFixed(2) + "s, volume=" + volume.toFixed(2)  
367 - ); 410 + + ", buffer=" + buffer_time.toFixed(2) + "s, max_buffer=" + max_buffer_time.toFixed(2) + "s, volume=" + volume.toFixed(2)
  411 + );
368 412
369 js_call_stop(); 413 js_call_stop();
370 414
@@ -375,46 +419,29 @@ package @@ -375,46 +419,29 @@ package
375 log("NetConnection: code=" + evt.info.code); 419 log("NetConnection: code=" + evt.info.code);
376 420
377 if (evt.info.hasOwnProperty("data") && evt.info.data) { 421 if (evt.info.hasOwnProperty("data") && evt.info.data) {
378 - if (evt.info.data.hasOwnProperty("srs_server")) {  
379 - srs_server = evt.info.data.srs_server;  
380 - }  
381 - if (evt.info.data.hasOwnProperty("srs_primary")) {  
382 - srs_primary = evt.info.data.srs_primary;  
383 - }  
384 - if (evt.info.data.hasOwnProperty("srs_authors")) {  
385 - srs_authors = evt.info.data.srs_authors;  
386 - }  
387 - if (evt.info.data.hasOwnProperty("srs_id")) {  
388 - srs_id = evt.info.data.srs_id;  
389 - }  
390 - if (evt.info.data.hasOwnProperty("srs_pid")) {  
391 - srs_pid = evt.info.data.srs_pid;  
392 - }  
393 - if (evt.info.data.hasOwnProperty("srs_server_ip")) {  
394 - srs_server_ip = evt.info.data.srs_server_ip;  
395 - } 422 + on_debug_info(evt.info.data);
396 update_context_items(); 423 update_context_items();
397 } 424 }
398 -  
399 - // reject by server, maybe redirect.  
400 - if (evt.info.code == "NetConnection.Connect.Rejected") {  
401 - // RTMP 302 redirect.  
402 - if (evt.info.hasOwnProperty("ex") && evt.info.ex.code == 302) {  
403 - var streamName:String = url.substr(url.lastIndexOf("/") + 1);  
404 - url = evt.info.ex.redirect + "/" + streamName;  
405 - log("Async RTMP 302 Redirect to: " + url);  
406 -  
407 - // notify server.  
408 - media_conn.call("Redirected", null, evt.info.ex.redirect);  
409 -  
410 - // do 302.  
411 - setTimeout(function(){  
412 - log("Async RTMP 302 Redirected.");  
413 - js_call_play(url, _width, _height, buffer_time, max_buffer_time, volume);  
414 - }, 1000);  
415 - return;  
416 - }  
417 - } 425 +
  426 + // reject by server, maybe redirect.
  427 + if (evt.info.code == "NetConnection.Connect.Rejected") {
  428 + // RTMP 302 redirect.
  429 + if (evt.info.hasOwnProperty("ex") && evt.info.ex.code == 302) {
  430 + var streamName:String = url.substr(url.lastIndexOf("/") + 1);
  431 + url = evt.info.ex.redirect + "/" + streamName;
  432 + log("Async RTMP 302 Redirect to: " + url);
  433 +
  434 + // notify server.
  435 + media_conn.call("Redirected", null, evt.info.ex.redirect);
  436 +
  437 + // do 302.
  438 + setTimeout(function(){
  439 + log("Async RTMP 302 Redirected.");
  440 + js_call_play(url, _width, _height, buffer_time, max_buffer_time, volume);
  441 + }, 1000);
  442 + return;
  443 + }
  444 + }
418 445
419 // TODO: FIXME: failed event. 446 // TODO: FIXME: failed event.
420 if (evt.info.code != "NetConnection.Connect.Success") { 447 if (evt.info.code != "NetConnection.Connect.Success") {
@@ -424,7 +451,7 @@ package @@ -424,7 +451,7 @@ package
424 media_stream = new NetStream(media_conn); 451 media_stream = new NetStream(media_conn);
425 media_stream.soundTransform = new SoundTransform(volume); 452 media_stream.soundTransform = new SoundTransform(volume);
426 media_stream.bufferTime = buffer_time; 453 media_stream.bufferTime = buffer_time;
427 - media_stream.bufferTimeMax = max_buffer_time; 454 + media_stream.bufferTimeMax = max_buffer_time;
428 media_stream.client = {}; 455 media_stream.client = {};
429 media_stream.client.onMetaData = system_on_metadata; 456 media_stream.client.onMetaData = system_on_metadata;
430 media_stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void { 457 media_stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
@@ -433,10 +460,10 @@ package @@ -433,10 +460,10 @@ package
433 if (evt.info.code == "NetStream.Video.DimensionChange") { 460 if (evt.info.code == "NetStream.Video.DimensionChange") {
434 system_on_metadata(media_metadata); 461 system_on_metadata(media_metadata);
435 } else if (evt.info.code == "NetStream.Buffer.Empty") { 462 } else if (evt.info.code == "NetStream.Buffer.Empty") {
436 - system_on_buffer_empty();  
437 - } else if (evt.info.code == "NetStream.Buffer.Full") {  
438 - system_on_buffer_full();  
439 - } 463 + system_on_buffer_empty();
  464 + } else if (evt.info.code == "NetStream.Buffer.Full") {
  465 + system_on_buffer_full();
  466 + }
440 467
441 // TODO: FIXME: failed event. 468 // TODO: FIXME: failed event.
442 }); 469 });
@@ -539,10 +566,10 @@ package @@ -539,10 +566,10 @@ package
539 566
540 // rescale to fs 567 // rescale to fs
541 __update_video_size(num, den, 568 __update_video_size(num, den,
542 - obj.width * user_fs_percent / 100,  
543 - obj.height * user_fs_percent / 100,  
544 - this.stage.fullScreenWidth, this.stage.fullScreenHeight  
545 - ); 569 + obj.width * user_fs_percent / 100,
  570 + obj.height * user_fs_percent / 100,
  571 + this.stage.fullScreenWidth, this.stage.fullScreenHeight
  572 + );
546 } 573 }
547 574
548 /** 575 /**
@@ -621,18 +648,18 @@ package @@ -621,18 +648,18 @@ package
621 this.control_fs_mask.graphics.drawRect(0, 0, _width, _height); 648 this.control_fs_mask.graphics.drawRect(0, 0, _width, _height);
622 this.control_fs_mask.graphics.endFill(); 649 this.control_fs_mask.graphics.endFill();
623 } 650 }
624 -  
625 - private function log(msg:String):void {  
626 - msg = "[" + new Date() +"][srs-player][" + js_id + "] " + msg;  
627 -  
628 - trace(msg);  
629 -  
630 - if (!flash.external.ExternalInterface.available) {  
631 - flash.utils.setTimeout(log, 300, msg);  
632 - return;  
633 - }  
634 -  
635 - ExternalInterface.call("console.log", msg);  
636 - } 651 +
  652 + private function log(msg:String):void {
  653 + msg = "[" + new Date() +"][srs-player][" + js_id + "] " + msg;
  654 +
  655 + trace(msg);
  656 +
  657 + if (!flash.external.ExternalInterface.available) {
  658 + flash.utils.setTimeout(log, 300, msg);
  659 + return;
  660 + }
  661 +
  662 + ExternalInterface.call("console.log", msg);
  663 + }
637 } 664 }
638 } 665 }