winlin

refine the ui buffer effect

@@ -234,7 +234,7 @@ SrsPlayer.prototype.on_player_metadata = function(metadata) { @@ -234,7 +234,7 @@ SrsPlayer.prototype.on_player_metadata = function(metadata) {
234 SrsPlayer.prototype.on_player_timer = function(time, buffer_length) { 234 SrsPlayer.prototype.on_player_timer = function(time, buffer_length) {
235 // ignore. 235 // ignore.
236 } 236 }
237 -function __srs_on_player_ready(id) { 237 +function __srs_find_player(id) {
238 for (var i = 0; i < SrsPlayer.__players.length; i++) { 238 for (var i = 0; i < SrsPlayer.__players.length; i++) {
239 var player = SrsPlayer.__players[i]; 239 var player = SrsPlayer.__players[i];
240 240
@@ -242,49 +242,34 @@ function __srs_on_player_ready(id) { @@ -242,49 +242,34 @@ function __srs_on_player_ready(id) {
242 continue; 242 continue;
243 } 243 }
244 244
245 - player.on_player_ready();  
246 - return; 245 + return player;
247 } 246 }
248 247
249 throw new Error("player not found. id=" + id); 248 throw new Error("player not found. id=" + id);
250 } 249 }
  250 +function __srs_on_player_ready(id) {
  251 + var player = __srs_find_player(id);
  252 + player.on_player_ready();
  253 +}
251 function __srs_on_player_metadata(id, metadata) { 254 function __srs_on_player_metadata(id, metadata) {
252 - for (var i = 0; i < SrsPlayer.__players.length; i++) {  
253 - var player = SrsPlayer.__players[i];  
254 -  
255 - if (player.id != id) {  
256 - continue;  
257 - }  
258 -  
259 - // user may override the on_player_metadata,  
260 - // so set the data before invoke it.  
261 - player.metadata = metadata;  
262 -  
263 - player.on_player_metadata(metadata);  
264 - return;  
265 - } 255 + var player = __srs_find_player(id);
266 256
267 - throw new Error("player not found. id=" + id); 257 + // user may override the on_player_metadata,
  258 + // so set the data before invoke it.
  259 + player.metadata = metadata;
  260 +
  261 + player.on_player_metadata(metadata);
268 } 262 }
269 function __srs_on_player_timer(id, time, buffer_length) { 263 function __srs_on_player_timer(id, time, buffer_length) {
270 - for (var i = 0; i < SrsPlayer.__players.length; i++) {  
271 - var player = SrsPlayer.__players[i];  
272 -  
273 - if (player.id != id) {  
274 - continue;  
275 - }  
276 -  
277 - buffer_length = Math.max(0, buffer_length);  
278 - buffer_length = Math.min(player.buffer_time, buffer_length);  
279 -  
280 - // user may override the on_player_timer,  
281 - // so set the data before invoke it.  
282 - player.time = time;  
283 - player.buffer_length = buffer_length;  
284 -  
285 - player.on_player_timer(time, buffer_length);  
286 - return;  
287 - } 264 + var player = __srs_find_player(id);
288 265
289 - throw new Error("player not found. id=" + id); 266 + buffer_length = Math.max(0, buffer_length);
  267 + buffer_length = Math.min(player.buffer_time, buffer_length);
  268 +
  269 + // user may override the on_player_timer,
  270 + // so set the data before invoke it.
  271 + player.time = time;
  272 + player.buffer_length = buffer_length;
  273 +
  274 + player.on_player_timer(time, buffer_length);
290 } 275 }
@@ -100,12 +100,16 @@ @@ -100,12 +100,16 @@
100 $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")"); 100 $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")");
101 select_dar("#btn_dar_original", 0, 0); 101 select_dar("#btn_dar_original", 0, 0);
102 select_fs_size("#btn_fs_size_screen_100", "screen", 100); 102 select_fs_size("#btn_fs_size_screen_100", "screen", 100);
103 - select_buffer_time("#btn_bt_0_8", 0.8);  
104 } 103 }
105 srs_player.on_player_timer = function(time, buffer_length) { 104 srs_player.on_player_timer = function(time, buffer_length) {
106 var buffer = buffer_length / srs_player.buffer_time * 100; 105 var buffer = buffer_length / srs_player.buffer_time * 100;
107 $("#pb_buffer").width(Number(buffer).toFixed(1) + "%"); 106 $("#pb_buffer").width(Number(buffer).toFixed(1) + "%");
108 107
  108 + // @remark, hack the default buffer time.
  109 + if (!__active_bt && time > 3) {
  110 + select_buffer_time("#btn_bt_2", 2);
  111 + }
  112 +
109 $("#pb_buffer_bg").attr("title", 113 $("#pb_buffer_bg").attr("title",
110 "缓冲区长度:" + Number(buffer_length).toFixed(1) + "秒(" 114 "缓冲区长度:" + Number(buffer_length).toFixed(1) + "秒("
111 + Number(buffer).toFixed(1) + "%)"); 115 + Number(buffer).toFixed(1) + "%)");
@@ -22,54 +22,60 @@ package @@ -22,54 +22,60 @@ package
22 public class srs_player extends Sprite 22 public class srs_player extends Sprite
23 { 23 {
24 // user set id. 24 // user set id.
25 - private var id:String = null; 25 + private var js_id:String = null;
26 // user set callback 26 // user set callback
27 - private var on_player_ready:String = null;  
28 - private var on_player_metadata:String = null;  
29 - private var on_player_timer:String = null; 27 + private var js_on_player_ready:String = null;
  28 + private var js_on_player_metadata:String = null;
  29 + private var js_on_player_timer:String = null;
30 30
31 // play param url. 31 // play param url.
32 - private var url:String = null; 32 + private var user_url:String = null;
33 // play param, user set width and height 33 // play param, user set width and height
34 - private var w:int = 0;  
35 - private var h:int = 0; 34 + private var user_w:int = 0;
  35 + private var user_h:int = 0;
36 // user set dar den:num 36 // user set dar den:num
37 - private var dar_num:int = 0;  
38 - private var dar_den:int = 0; 37 + private var user_dar_num:int = 0;
  38 + private var user_dar_den:int = 0;
39 // user set fs(fullscreen) refer and percent. 39 // user set fs(fullscreen) refer and percent.
40 - private var fs_refer:String = null;  
41 - private var fs_percent:int = 0; 40 + private var user_fs_refer:String = null;
  41 + private var user_fs_percent:int = 0;
42 42
43 - private var conn:NetConnection = null;  
44 - private var stream:NetStream = null;  
45 - private var video:Video = null;  
46 - private var metadata:Object = {};  
47 - private var timer:Timer = new Timer(300); 43 + // media specified.
  44 + private var media_conn:NetConnection = null;
  45 + private var media_stream:NetStream = null;
  46 + private var media_video:Video = null;
  47 + private var media_metadata:Object = {};
  48 + private var media_timer:Timer = new Timer(300);
48 49
  50 + // controls.
49 // flash donot allow js to set to fullscreen, 51 // flash donot allow js to set to fullscreen,
50 // only allow user click to enter fullscreen. 52 // only allow user click to enter fullscreen.
51 - private var fs_mask:Sprite = new Sprite(); 53 + private var control_fs_mask:Sprite = new Sprite();
52 54
53 public function srs_player() 55 public function srs_player()
54 { 56 {
55 - flash.system.Security.allowDomain("*");  
56 -  
57 if (!this.stage) { 57 if (!this.stage) {
58 - this.addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage); 58 + this.addEventListener(Event.ADDED_TO_STAGE, this.system_on_add_to_stage);
59 } else { 59 } else {
60 - this.onAddToStage(null); 60 + this.system_on_add_to_stage(null);
61 } 61 }
62 } 62 }
63 63
64 - private function onAddToStage(evt:Event):void { 64 + /**
  65 + * system event callback, when this control added to stage.
  66 + * the main function.
  67 + */
  68 + private function system_on_add_to_stage(evt:Event):void {
  69 + this.removeEventListener(Event.ADDED_TO_STAGE, this.system_on_add_to_stage);
  70 +
65 this.stage.align = StageAlign.TOP_LEFT; 71 this.stage.align = StageAlign.TOP_LEFT;
66 this.stage.scaleMode = StageScaleMode.NO_SCALE; 72 this.stage.scaleMode = StageScaleMode.NO_SCALE;
67 73
68 - this.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.on_stage_fullscreen); 74 + this.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.user_on_stage_fullscreen);
69 75
70 - this.addChild(this.fs_mask);  
71 - this.fs_mask.buttonMode = true;  
72 - this.fs_mask.addEventListener(MouseEvent.CLICK, on_user_click_video); 76 + this.addChild(this.control_fs_mask);
  77 + this.control_fs_mask.buttonMode = true;
  78 + this.control_fs_mask.addEventListener(MouseEvent.CLICK, user_on_click_video);
73 79
74 this.contextMenu = new ContextMenu(); 80 this.contextMenu = new ContextMenu();
75 this.contextMenu.hideBuiltInItems(); 81 this.contextMenu.hideBuiltInItems();
@@ -83,63 +89,132 @@ package @@ -83,63 +89,132 @@ package
83 throw new Error("must specifies the on_player_ready"); 89 throw new Error("must specifies the on_player_ready");
84 } 90 }
85 91
86 - this.id = flashvars.id;  
87 - this.on_player_ready = flashvars.on_player_ready;  
88 - this.on_player_metadata = flashvars.on_player_metadata;  
89 - this.on_player_timer = flashvars.on_player_timer; 92 + this.js_id = flashvars.id;
  93 + this.js_on_player_ready = flashvars.on_player_ready;
  94 + this.js_on_player_metadata = flashvars.on_player_metadata;
  95 + this.js_on_player_timer = flashvars.on_player_timer;
  96 +
  97 + this.media_timer.addEventListener(TimerEvent.TIMER, this.system_on_timer);
  98 + this.media_timer.start();
  99 +
  100 + flash.utils.setTimeout(this.system_on_js_ready, 0);
  101 + }
  102 +
  103 + /**
  104 + * system callack event, when js ready, register callback for js.
  105 + * the actual main function.
  106 + */
  107 + private function system_on_js_ready():void {
  108 + if (!flash.external.ExternalInterface.available) {
  109 + trace("js not ready, try later.");
  110 + flash.utils.setTimeout(this.system_on_js_ready, 100);
  111 + return;
  112 + }
90 113
91 - this.timer.addEventListener(TimerEvent.TIMER, this.on_timer);  
92 - this.timer.start(); 114 + flash.external.ExternalInterface.addCallback("__play", this.js_call_play);
  115 + flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop);
  116 + flash.external.ExternalInterface.addCallback("__pause", this.js_call_pause);
  117 + flash.external.ExternalInterface.addCallback("__resume", this.js_call_resume);
  118 + flash.external.ExternalInterface.addCallback("__dar", this.js_call_dar);
  119 + flash.external.ExternalInterface.addCallback("__set_fs", this.js_call_set_fs_size);
  120 + flash.external.ExternalInterface.addCallback("__set_bt", this.js_call_set_bt);
93 121
94 - flash.utils.setTimeout(this.on_js_ready, 0); 122 + flash.external.ExternalInterface.call(this.js_on_player_ready, this.js_id);
95 } 123 }
96 124
97 - private function on_timer(evt:TimerEvent):void {  
98 - if (!this.stream) { 125 + /**
  126 + * system callack event, timer to do some regular tasks.
  127 + */
  128 + private function system_on_timer(evt:TimerEvent):void {
  129 + if (!this.media_stream) {
99 trace("stream is null, ignore timer event."); 130 trace("stream is null, ignore timer event.");
100 return; 131 return;
101 } 132 }
102 133
103 trace("notify js the timer event."); 134 trace("notify js the timer event.");
104 flash.external.ExternalInterface.call( 135 flash.external.ExternalInterface.call(
105 - this.on_player_timer, this.id, this.stream.time, this.stream.bufferLength); 136 + this.js_on_player_timer, this.js_id, this.media_stream.time, this.media_stream.bufferLength);
  137 + }
  138 +
  139 + /**
  140 + * system callack event, when got metadata from stream.
  141 + * or got video dimension change event(the DAR notification), to update the metadata manually.
  142 + */
  143 + private function system_on_metadata(metadata:Object):void {
  144 + this.media_metadata = metadata;
  145 +
  146 + // for context menu
  147 + var customItems:Array = [new ContextMenuItem("SrsPlayer")];
  148 + if (metadata.hasOwnProperty("server")) {
  149 + customItems.push(new ContextMenuItem("Server: " + metadata.server));
  150 + }
  151 + if (metadata.hasOwnProperty("contributor")) {
  152 + customItems.push(new ContextMenuItem("Contributor: " + metadata.contributor));
  153 + }
  154 + contextMenu.customItems = customItems;
  155 +
  156 + // for js.
  157 + var obj:Object = __get_video_size_object();
  158 +
  159 + obj.server = 'srs';
  160 + obj.contributor = 'winlin';
  161 +
  162 + if (metadata.hasOwnProperty("server")) {
  163 + obj.server = metadata.server;
  164 + }
  165 + if (metadata.hasOwnProperty("contributor")) {
  166 + obj.contributor = metadata.contributor;
  167 + }
  168 +
  169 + var code:int = flash.external.ExternalInterface.call(js_on_player_metadata, js_id, obj);
  170 + if (code != 0) {
  171 + throw new Error("callback on_player_metadata failed. code=" + code);
  172 + }
106 } 173 }
107 174
108 - private function on_stage_fullscreen(evt:FullScreenEvent):void { 175 + /**
  176 + * player callack event, when user click video to enter or leave fullscreen.
  177 + */
  178 + private function user_on_stage_fullscreen(evt:FullScreenEvent):void {
109 if (!evt.fullScreen) { 179 if (!evt.fullScreen) {
110 - execute_user_set_dar(); 180 + __execute_user_set_dar();
111 } else { 181 } else {
112 - execute_user_enter_fullscreen(); 182 + __execute_user_enter_fullscreen();
113 } 183 }
114 } 184 }
115 185
116 - private function on_js_ready():void {  
117 - if (!flash.external.ExternalInterface.available) {  
118 - trace("js not ready, try later.");  
119 - flash.utils.setTimeout(this.on_js_ready, 100); 186 + /**
  187 + * user event callback, js cannot enter the fullscreen mode, user must click to.
  188 + */
  189 + private function user_on_click_video(evt:MouseEvent):void {
  190 + if (!this.stage.allowsFullScreen) {
  191 + trace("donot allow fullscreen.");
120 return; 192 return;
121 } 193 }
122 194
123 - flash.external.ExternalInterface.addCallback("__play", this.js_call_play);  
124 - flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop);  
125 - flash.external.ExternalInterface.addCallback("__pause", this.js_call_pause);  
126 - flash.external.ExternalInterface.addCallback("__resume", this.js_call_resume);  
127 - flash.external.ExternalInterface.addCallback("__dar", this.js_call_dar);  
128 - flash.external.ExternalInterface.addCallback("__set_fs", this.js_call_set_fs_size);  
129 - flash.external.ExternalInterface.addCallback("__set_bt", this.js_call_set_bt);  
130 -  
131 - flash.external.ExternalInterface.call(this.on_player_ready, this.id); 195 + // enter fullscreen to get the fullscreen size correctly.
  196 + if (this.stage.displayState == StageDisplayState.FULL_SCREEN) {
  197 + this.stage.displayState = StageDisplayState.NORMAL;
  198 + } else {
  199 + this.stage.displayState = StageDisplayState.FULL_SCREEN;
  200 + }
132 } 201 }
133 202
  203 + /**
  204 + * function for js to call: to pause the stream. ignore if not play.
  205 + */
134 private function js_call_pause():void { 206 private function js_call_pause():void {
135 - if (this.stream) {  
136 - this.stream.pause(); 207 + if (this.media_stream) {
  208 + this.media_stream.pause();
137 } 209 }
138 } 210 }
139 211
  212 + /**
  213 + * function for js to call: to resume the stream. ignore if not play.
  214 + */
140 private function js_call_resume():void { 215 private function js_call_resume():void {
141 - if (this.stream) {  
142 - this.stream.resume(); 216 + if (this.media_stream) {
  217 + this.media_stream.resume();
143 } 218 }
144 } 219 }
145 220
@@ -153,10 +228,10 @@ package @@ -153,10 +228,10 @@ package
153 * use user specified width if -1. 228 * use user specified width if -1.
154 */ 229 */
155 private function js_call_dar(num:int, den:int):void { 230 private function js_call_dar(num:int, den:int):void {
156 - dar_num = num;  
157 - dar_den = den; 231 + user_dar_num = num;
  232 + user_dar_den = den;
158 233
159 - flash.utils.setTimeout(execute_user_set_dar, 0); 234 + flash.utils.setTimeout(__execute_user_set_dar, 0);
160 } 235 }
161 236
162 /** 237 /**
@@ -168,24 +243,8 @@ package @@ -168,24 +243,8 @@ package
168 * 100 means 100%. 243 * 100 means 100%.
169 */ 244 */
170 private function js_call_set_fs_size(refer:String, percent:int):void { 245 private function js_call_set_fs_size(refer:String, percent:int):void {
171 - fs_refer = refer;  
172 - fs_percent = percent;  
173 - }  
174 - /**  
175 - * js cannot enter the fullscreen mode, user must click to.  
176 - */  
177 - private function on_user_click_video(evt:MouseEvent):void {  
178 - if (!this.stage.allowsFullScreen) {  
179 - trace("donot allow fullscreen.");  
180 - return;  
181 - }  
182 -  
183 - // enter fullscreen to get the fullscreen size correctly.  
184 - if (this.stage.displayState == StageDisplayState.FULL_SCREEN) {  
185 - this.stage.displayState = StageDisplayState.NORMAL;  
186 - } else {  
187 - this.stage.displayState = StageDisplayState.FULL_SCREEN;  
188 - } 246 + user_fs_refer = refer;
  247 + user_fs_percent = percent;
189 } 248 }
190 249
191 /** 250 /**
@@ -193,50 +252,48 @@ package @@ -193,50 +252,48 @@ package
193 * @buffer_time the buffer time in seconds. 252 * @buffer_time the buffer time in seconds.
194 */ 253 */
195 private function js_call_set_bt(buffer_time:Number):void { 254 private function js_call_set_bt(buffer_time:Number):void {
196 - if (this.stream) {  
197 - this.stream.bufferTime = buffer_time; 255 + if (this.media_stream) {
  256 + this.media_stream.bufferTime = buffer_time;
198 } 257 }
199 } 258 }
200 259
  260 + /**
  261 + * function for js to call: to stop the stream. ignore if not play.
  262 + */
201 private function js_call_stop():void { 263 private function js_call_stop():void {
202 - if (this.stream) {  
203 - this.stream.close();  
204 - this.stream = null; 264 + if (this.media_stream) {
  265 + this.media_stream.close();
  266 + this.media_stream = null;
205 } 267 }
206 - if (this.conn) {  
207 - this.conn.close();  
208 - this.conn = null; 268 + if (this.media_conn) {
  269 + this.media_conn.close();
  270 + this.media_conn = null;
209 } 271 }
210 - if (this.video) {  
211 - this.removeChild(this.video);  
212 - this.video = null; 272 + if (this.media_video) {
  273 + this.removeChild(this.media_video);
  274 + this.media_video = null;
213 } 275 }
214 } 276 }
215 277
216 - private function draw_black_background(_width:int, _height:int):void {  
217 - // draw black bg.  
218 - this.graphics.beginFill(0x00, 1.0);  
219 - this.graphics.drawRect(0, 0, _width, _height);  
220 - this.graphics.endFill();  
221 -  
222 - // draw the fs mask.  
223 - this.fs_mask.graphics.beginFill(0xff0000, 0);  
224 - this.fs_mask.graphics.drawRect(0, 0, _width, _height);  
225 - this.fs_mask.graphics.endFill();  
226 - }  
227 -  
228 - private function js_call_play(url:String, _width:int, _height:int, _buffer_time:Number):void {  
229 - this.url = url;  
230 - this.w = _width;  
231 - this.h = _height;  
232 - trace("start to play url: " + this.url + ", w=" + this.w + ", h=" + this.h); 278 + /**
  279 + * function for js to call: to play the stream. stop then play.
  280 + * @param url, the rtmp/http url to play.
  281 + * @param _width, the player width.
  282 + * @param _height, the player height.
  283 + * @param buffer_time, the buffer time in seconds. recommend to >=0.5
  284 + */
  285 + private function js_call_play(url:String, _width:int, _height:int, buffer_time:Number):void {
  286 + this.user_url = url;
  287 + this.user_w = _width;
  288 + this.user_h = _height;
  289 + trace("start to play url: " + this.user_url + ", w=" + this.user_w + ", h=" + this.user_h);
233 290
234 js_call_stop(); 291 js_call_stop();
235 292
236 - this.conn = new NetConnection();  
237 - this.conn.client = {};  
238 - this.conn.client.onBWDone = function():void {};  
239 - this.conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void { 293 + this.media_conn = new NetConnection();
  294 + this.media_conn.client = {};
  295 + this.media_conn.client.onBWDone = function():void {};
  296 + this.media_conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
240 trace ("NetConnection: code=" + evt.info.code); 297 trace ("NetConnection: code=" + evt.info.code);
241 298
242 // TODO: FIXME: failed event. 299 // TODO: FIXME: failed event.
@@ -244,77 +301,45 @@ package @@ -244,77 +301,45 @@ package
244 return; 301 return;
245 } 302 }
246 303
247 - stream = new NetStream(conn);  
248 - stream.bufferTime = _buffer_time;  
249 - stream.client = {};  
250 - stream.client.onMetaData = on_metadata;  
251 - stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void { 304 + media_stream = new NetStream(media_conn);
  305 + media_stream.bufferTime = buffer_time;
  306 + media_stream.client = {};
  307 + media_stream.client.onMetaData = system_on_metadata;
  308 + media_stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
252 trace ("NetStream: code=" + evt.info.code); 309 trace ("NetStream: code=" + evt.info.code);
253 310
254 if (evt.info.code == "NetStream.Video.DimensionChange") { 311 if (evt.info.code == "NetStream.Video.DimensionChange") {
255 - on_metadata(metadata); 312 + system_on_metadata(media_metadata);
256 } 313 }
257 314
258 // TODO: FIXME: failed event. 315 // TODO: FIXME: failed event.
259 }); 316 });
260 317
261 if (url.indexOf("http") == 0) { 318 if (url.indexOf("http") == 0) {
262 - stream.play(url); 319 + media_stream.play(url);
263 } else { 320 } else {
264 var streamName:String = url.substr(url.lastIndexOf("/")); 321 var streamName:String = url.substr(url.lastIndexOf("/"));
265 - stream.play(streamName); 322 + media_stream.play(streamName);
266 } 323 }
267 324
268 - video = new Video();  
269 - video.width = _width;  
270 - video.height = _height;  
271 - video.attachNetStream(stream);  
272 - video.smoothing = true;  
273 - addChild(video); 325 + media_video = new Video();
  326 + media_video.width = _width;
  327 + media_video.height = _height;
  328 + media_video.attachNetStream(media_stream);
  329 + media_video.smoothing = true;
  330 + addChild(media_video);
274 331
275 - draw_black_background(_width, _height); 332 + __draw_black_background(_width, _height);
276 333
277 // lowest layer, for mask to cover it. 334 // lowest layer, for mask to cover it.
278 - setChildIndex(video, 0); 335 + setChildIndex(media_video, 0);
279 }); 336 });
280 337
281 if (url.indexOf("http") == 0) { 338 if (url.indexOf("http") == 0) {
282 - this.conn.connect(null); 339 + this.media_conn.connect(null);
283 } else { 340 } else {
284 - var tcUrl:String = this.url.substr(0, this.url.lastIndexOf("/"));  
285 - this.conn.connect(tcUrl);  
286 - }  
287 - }  
288 -  
289 - private function on_metadata(metadata:Object):void {  
290 - this.metadata = metadata;  
291 -  
292 - // for context menu  
293 - var customItems:Array = [new ContextMenuItem("SrsPlayer")];  
294 - if (metadata.hasOwnProperty("server")) {  
295 - customItems.push(new ContextMenuItem("Server: " + metadata.server));  
296 - }  
297 - if (metadata.hasOwnProperty("contributor")) {  
298 - customItems.push(new ContextMenuItem("Contributor: " + metadata.contributor));  
299 - }  
300 - contextMenu.customItems = customItems;  
301 -  
302 - // for js.  
303 - var obj:Object = get_video_size_object();  
304 -  
305 - obj.server = 'srs';  
306 - obj.contributor = 'winlin';  
307 -  
308 - if (metadata.hasOwnProperty("server")) {  
309 - obj.server = metadata.server;  
310 - }  
311 - if (metadata.hasOwnProperty("contributor")) {  
312 - obj.contributor = metadata.contributor;  
313 - }  
314 -  
315 - var code:int = flash.external.ExternalInterface.call(on_player_metadata, id, obj);  
316 - if (code != 0) {  
317 - throw new Error("callback on_player_metadata failed. code=" + code); 341 + var tcUrl:String = this.user_url.substr(0, this.user_url.lastIndexOf("/"));
  342 + this.media_conn.connect(tcUrl);
318 } 343 }
319 } 344 }
320 345
@@ -324,26 +349,26 @@ package @@ -324,26 +349,26 @@ package
324 * 2. override with metadata size if specified. 349 * 2. override with metadata size if specified.
325 * 3. override with codec size if specified. 350 * 3. override with codec size if specified.
326 */ 351 */
327 - private function get_video_size_object():Object { 352 + private function __get_video_size_object():Object {
328 var obj:Object = { 353 var obj:Object = {
329 - width: video.width,  
330 - height: video.height 354 + width: media_video.width,
  355 + height: media_video.height
331 }; 356 };
332 357
333 // override with metadata size. 358 // override with metadata size.
334 - if (metadata.hasOwnProperty("width")) {  
335 - obj.width = metadata.width; 359 + if (this.media_metadata.hasOwnProperty("width")) {
  360 + obj.width = this.media_metadata.width;
336 } 361 }
337 - if (metadata.hasOwnProperty("height")) {  
338 - obj.height = metadata.height; 362 + if (this.media_metadata.hasOwnProperty("height")) {
  363 + obj.height = this.media_metadata.height;
339 } 364 }
340 365
341 // override with codec size. 366 // override with codec size.
342 - if (video.videoWidth > 0) {  
343 - obj.width = video.videoWidth; 367 + if (media_video.videoWidth > 0) {
  368 + obj.width = media_video.videoWidth;
344 } 369 }
345 - if (video.videoHeight > 0) {  
346 - obj.height = video.videoHeight; 370 + if (media_video.videoHeight > 0) {
  371 + obj.height = media_video.videoHeight;
347 } 372 }
348 373
349 return obj; 374 return obj;
@@ -352,17 +377,17 @@ package @@ -352,17 +377,17 @@ package
352 /** 377 /**
353 * execute the enter fullscreen action. 378 * execute the enter fullscreen action.
354 */ 379 */
355 - private function execute_user_enter_fullscreen():void {  
356 - if (!fs_refer || fs_percent <= 0) { 380 + private function __execute_user_enter_fullscreen():void {
  381 + if (!user_fs_refer || user_fs_percent <= 0) {
357 return; 382 return;
358 } 383 }
359 384
360 // change to video size if refer to video. 385 // change to video size if refer to video.
361 - var obj:Object = get_video_size_object(); 386 + var obj:Object = __get_video_size_object();
362 387
363 // get the DAR 388 // get the DAR
364 - var num:int = dar_num;  
365 - var den:int = dar_den; 389 + var num:int = user_dar_num;
  390 + var den:int = user_dar_den;
366 391
367 if (num == 0) { 392 if (num == 0) {
368 num = obj.height; 393 num = obj.height;
@@ -379,7 +404,7 @@ package @@ -379,7 +404,7 @@ package
379 } 404 }
380 405
381 // for refer is screen. 406 // for refer is screen.
382 - if (fs_refer == "screen") { 407 + if (user_fs_refer == "screen") {
383 obj = { 408 obj = {
384 width: this.stage.fullScreenWidth, 409 width: this.stage.fullScreenWidth,
385 height: this.stage.fullScreenHeight 410 height: this.stage.fullScreenHeight
@@ -387,34 +412,34 @@ package @@ -387,34 +412,34 @@ package
387 } 412 }
388 413
389 // rescale to fs 414 // rescale to fs
390 - update_video_size(num, den, obj.width * fs_percent / 100, obj.height * fs_percent / 100, this.stage.fullScreenWidth, this.stage.fullScreenHeight); 415 + __update_video_size(num, den, obj.width * user_fs_percent / 100, obj.height * user_fs_percent / 100, this.stage.fullScreenWidth, this.stage.fullScreenHeight);
391 } 416 }
392 417
393 /** 418 /**
394 * for user set dar, or leave fullscreen to recover the dar. 419 * for user set dar, or leave fullscreen to recover the dar.
395 */ 420 */
396 - private function execute_user_set_dar():void { 421 + private function __execute_user_set_dar():void {
397 // get the DAR 422 // get the DAR
398 - var num:int = dar_num;  
399 - var den:int = dar_den; 423 + var num:int = user_dar_num;
  424 + var den:int = user_dar_den;
400 425
401 - var obj:Object = get_video_size_object(); 426 + var obj:Object = __get_video_size_object();
402 427
403 if (num == 0) { 428 if (num == 0) {
404 num = obj.height; 429 num = obj.height;
405 } 430 }
406 if (num == -1) { 431 if (num == -1) {
407 - num = this.h; 432 + num = this.user_h;
408 } 433 }
409 434
410 if (den == 0) { 435 if (den == 0) {
411 den = obj.width; 436 den = obj.width;
412 } 437 }
413 if (den == -1) { 438 if (den == -1) {
414 - den = this.w; 439 + den = this.user_w;
415 } 440 }
416 441
417 - update_video_size(num, den, this.w, this.h, this.w, this.h); 442 + __update_video_size(num, den, this.user_w, this.user_h, this.user_w, this.user_h);
418 } 443 }
419 444
420 /** 445 /**
@@ -426,8 +451,8 @@ package @@ -426,8 +451,8 @@ package
426 * @param _w/_h the video draw paper size. used to rescale the player together with DAR. 451 * @param _w/_h the video draw paper size. used to rescale the player together with DAR.
427 * @param _sw/_wh the stage size, >= paper size. used to center the player. 452 * @param _sw/_wh the stage size, >= paper size. used to center the player.
428 */ 453 */
429 - private function update_video_size(_num:int, _den:int, _w:int, _h:int, _sw:int, _sh:int):void {  
430 - if (!this.video || _num <= 0 || _den <= 0) { 454 + private function __update_video_size(_num:int, _den:int, _w:int, _h:int, _sw:int, _sh:int):void {
  455 + if (!this.media_video || _num <= 0 || _den <= 0) {
431 return; 456 return;
432 } 457 }
433 458
@@ -435,21 +460,36 @@ package @@ -435,21 +460,36 @@ package
435 // calc the height by DAR 460 // calc the height by DAR
436 var _height:int = _w * _num / _den; 461 var _height:int = _w * _num / _den;
437 if (_height <= _h) { 462 if (_height <= _h) {
438 - this.video.width = _w;  
439 - this.video.height = _height; 463 + this.media_video.width = _w;
  464 + this.media_video.height = _height;
440 } else { 465 } else {
441 // height overflow, calc the width by DAR 466 // height overflow, calc the width by DAR
442 var _width:int = _h * _den / _num; 467 var _width:int = _h * _den / _num;
443 468
444 - this.video.width = _width;  
445 - this.video.height = _h; 469 + this.media_video.width = _width;
  470 + this.media_video.height = _h;
446 } 471 }
447 472
448 // align center. 473 // align center.
449 - this.video.x = (_sw - this.video.width) / 2;  
450 - this.video.y = (_sh - this.video.height) / 2; 474 + this.media_video.x = (_sw - this.media_video.width) / 2;
  475 + this.media_video.y = (_sh - this.media_video.height) / 2;
451 476
452 - draw_black_background(_sw, _sh); 477 + __draw_black_background(_sw, _sh);
  478 + }
  479 +
  480 + /**
  481 + * draw black background and draw the fullscreen mask.
  482 + */
  483 + private function __draw_black_background(_width:int, _height:int):void {
  484 + // draw black bg.
  485 + this.graphics.beginFill(0x00, 1.0);
  486 + this.graphics.drawRect(0, 0, _width, _height);
  487 + this.graphics.endFill();
  488 +
  489 + // draw the fs mask.
  490 + this.control_fs_mask.graphics.beginFill(0xff0000, 0);
  491 + this.control_fs_mask.graphics.drawRect(0, 0, _width, _height);
  492 + this.control_fs_mask.graphics.endFill();
453 } 493 }
454 } 494 }
455 } 495 }