winlin

refine ui, unify the player size

@@ -80,11 +80,19 @@ function build_default_hls_url() { @@ -80,11 +80,19 @@ function build_default_hls_url() {
80 } 80 }
81 81
82 /** 82 /**
  83 +* player specified size.
  84 +*/
  85 +function srs_get_player_modal() { return 740; }
  86 +function srs_get_player_width() { return srs_get_player_modal() - 30; }
  87 +function srs_get_player_height() { return srs_get_player_width() * 9 / 19; }
  88 +
  89 +/**
83 * initialize the page. 90 * initialize the page.
84 -* @param rtmp_url the rtmp stream url to play  
85 -* @param hls_url the hls stream url to play 91 +* @param rtmp_url the div id contains the rtmp stream url to play
  92 +* @param hls_url the div id contains the hls stream url to play
  93 +* @param modal_player the div id contains the modal player
86 */ 94 */
87 -function srs_init(rtmp_url, hls_url) { 95 +function srs_init(rtmp_url, hls_url, modal_player) {
88 update_nav(); 96 update_nav();
89 97
90 if (rtmp_url) { 98 if (rtmp_url) {
@@ -93,6 +101,10 @@ function srs_init(rtmp_url, hls_url) { @@ -93,6 +101,10 @@ function srs_init(rtmp_url, hls_url) {
93 if (hls_url) { 101 if (hls_url) {
94 $(hls_url).val(build_default_hls_url()); 102 $(hls_url).val(build_default_hls_url());
95 } 103 }
  104 + if (modal_player) {
  105 + $(modal_player).width(srs_get_player_modal() + "px");
  106 + $(modal_player).css("margin-left", "-" + srs_get_player_modal() / 2 +"px");
  107 + }
96 } 108 }
97 109
98 ////////////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////////////
@@ -11,6 +11,10 @@ @@ -11,6 +11,10 @@
11 body{ 11 body{
12 padding-top: 55px; 12 padding-top: 55px;
13 } 13 }
  14 + #main_modal {
  15 + width: 700px;
  16 + margin-left: -350px;
  17 + }
14 </style> 18 </style>
15 <script type="text/javascript" src="js/jwplayer.js" ></script> 19 <script type="text/javascript" src="js/jwplayer.js" ></script>
16 <script type='text/javascript'>jwplayer.key = 'N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ=='; </script> 20 <script type='text/javascript'>jwplayer.key = 'N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ=='; </script>
@@ -21,7 +25,7 @@ @@ -21,7 +25,7 @@
21 // get the vhost and port to set the default url. 25 // get the vhost and port to set the default url.
22 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo 26 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
23 // url set to: rtmp://demo:1935/live/livestream 27 // url set to: rtmp://demo:1935/live/livestream
24 - srs_init("#txt_rtmp_url", "#txt_hls_url"); 28 + srs_init("#txt_rtmp_url", "#txt_hls_url", "#main_modal");
25 29
26 $("#main_modal").on("hide", function(){ 30 $("#main_modal").on("hide", function(){
27 $("#div_container").remove(); 31 $("#div_container").remove();
@@ -42,8 +46,8 @@ @@ -42,8 +46,8 @@
42 46
43 var conf = { 47 var conf = {
44 file: _url, 48 file: _url,
45 - width: "530",  
46 - height: "300", 49 + width: srs_get_player_width(),
  50 + height: srs_get_player_height(),
47 autostart: true, 51 autostart: true,
48 analytics: { enabled: false} 52 analytics: { enabled: false}
49 }; 53 };
@@ -12,6 +12,10 @@ @@ -12,6 +12,10 @@
12 body{ 12 body{
13 padding-top: 55px; 13 padding-top: 55px;
14 } 14 }
  15 + #main_modal {
  16 + width: 700px;
  17 + margin-left: -350px;
  18 + }
15 </style> 19 </style>
16 <script type="text/javascript"> 20 <script type="text/javascript">
17 function osmf_play(url) { 21 function osmf_play(url) {
@@ -41,7 +45,7 @@ @@ -41,7 +45,7 @@
41 45
42 swfobject.embedSWF( 46 swfobject.embedSWF(
43 "js/StrobeMediaPlayback.swf", "player_id", 47 "js/StrobeMediaPlayback.swf", "player_id",
44 - 530, 300, 48 + srs_get_player_width(), srs_get_player_height(),
45 "11.1", "js/AdobeFlashPlayerInstall.swf", 49 "11.1", "js/AdobeFlashPlayerInstall.swf",
46 flashvars, params, attributes 50 flashvars, params, attributes
47 ); 51 );
@@ -50,7 +54,7 @@ @@ -50,7 +54,7 @@
50 // get the vhost and port to set the default url. 54 // get the vhost and port to set the default url.
51 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo 55 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
52 // url set to: rtmp://demo:1935/live/livestream 56 // url set to: rtmp://demo:1935/live/livestream
53 - srs_init($("#txt_url")); 57 + srs_init("#txt_url", null, "#main_modal");
54 58
55 $("#main_modal").on("hide", function(){ 59 $("#main_modal").on("hide", function(){
56 osmf_play("http://localhost"); 60 osmf_play("http://localhost");
@@ -12,6 +12,17 @@ @@ -12,6 +12,17 @@
12 body{ 12 body{
13 padding-top: 55px; 13 padding-top: 55px;
14 } 14 }
  15 + #my_modal_footer {
  16 + margin-top: -20px;
  17 + padding-top: 3px;
  18 + }
  19 + #div_play_time {
  20 + margin-top: 10px;
  21 + }
  22 + #pb_buffer_bg {
  23 + margin-top: -4px;
  24 + margin-bottom: 10px;
  25 + }
15 </style> 26 </style>
16 <script type="text/javascript"> 27 <script type="text/javascript">
17 var srs_player = null; 28 var srs_player = null;
@@ -56,7 +67,7 @@ @@ -56,7 +67,7 @@
56 // get the vhost and port to set the default url. 67 // get the vhost and port to set the default url.
57 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo 68 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
58 // url set to: rtmp://demo:1935/live/livestream 69 // url set to: rtmp://demo:1935/live/livestream
59 - srs_init($("#txt_url")); 70 + srs_init("#txt_url", null, "#main_modal");
60 71
61 $("#fs_tips").tooltip({ 72 $("#fs_tips").tooltip({
62 title: "点击视频进入或退出全屏" 73 title: "点击视频进入或退出全屏"
@@ -80,7 +91,8 @@ @@ -80,7 +91,8 @@
80 91
81 var url = $("#txt_url").val(); 92 var url = $("#txt_url").val();
82 93
83 - srs_player = new SrsPlayer("player_id", url, 530, 300); 94 + srs_player = new SrsPlayer("player_id", url,
  95 + srs_get_player_width(), srs_get_player_height());
84 srs_player.on_player_ready = function() { 96 srs_player.on_player_ready = function() {
85 srs_player.play(); 97 srs_player.play();
86 } 98 }
@@ -240,7 +252,7 @@ @@ -240,7 +252,7 @@
240 <div id="main_modal" class="modal hide fade"> 252 <div id="main_modal" class="modal hide fade">
241 <div class="modal-header"> 253 <div class="modal-header">
242 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 254 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
243 - <h3>SrsPlayer</h3> 255 + <h3><a href="https://github.com/winlinvip/simple-rtmp-server">SrsPlayer</a></h3>
244 </div> 256 </div>
245 <div class="modal-body"> 257 <div class="modal-body">
246 <div id="player"></div> 258 <div id="player"></div>
@@ -248,8 +260,8 @@ @@ -248,8 +260,8 @@
248 <div class="bar" style="width: 0%;" id="pb_buffer"></div> 260 <div class="bar" style="width: 0%;" id="pb_buffer"></div>
249 </div> 261 </div>
250 </div> 262 </div>
251 - <div class="modal-footer" style="margin-top:-20px;">  
252 - <div class="input-prepend" style="margin-top: 10px;"> 263 + <div class="modal-footer" id="my_modal_footer">
  264 + <div class="input-prepend" id="div_play_time">
253 <span class="add-on" title="播放时长">@T</span> 265 <span class="add-on" title="播放时长">@T</span>
254 <input class="span2" style="width:85px" id="txt_time" type="text" placeholder="天 时:分:秒"> 266 <input class="span2" style="width:85px" id="txt_time" type="text" placeholder="天 时:分:秒">
255 </div> 267 </div>
@@ -258,7 +270,7 @@ @@ -258,7 +270,7 @@
258 <a id="fs_tips" href="#" data-toggle="tooltip" data-placement="top" title=""> 270 <a id="fs_tips" href="#" data-toggle="tooltip" data-placement="top" title="">
259 <img src="img/tooltip.png"/> 271 <img src="img/tooltip.png"/>
260 </a> 272 </a>
261 - 大小<span class="caret"></span> 273 + 全屏大小<span class="caret"></span>
262 </button> 274 </button>
263 <ul class="dropdown-menu"> 275 <ul class="dropdown-menu">
264 <li><a id="btn_fs_size_screen_100" href="#">屏幕大小(100%)</a></li> 276 <li><a id="btn_fs_size_screen_100" href="#">屏幕大小(100%)</a></li>
@@ -270,11 +282,11 @@ @@ -270,11 +282,11 @@
270 </ul> 282 </ul>
271 </div> 283 </div>
272 <div class="btn-group dropup"> 284 <div class="btn-group dropup">
273 - <button class="btn dropdown-toggle" data-toggle="dropdown">比例<span class="caret"></span></button> 285 + <button class="btn dropdown-toggle" data-toggle="dropdown">显示比例<span class="caret"></span></button>
274 <ul class="dropdown-menu"> 286 <ul class="dropdown-menu">
275 <li><a id="btn_dar_original" href="#">视频原始比例</a></li> 287 <li><a id="btn_dar_original" href="#">视频原始比例</a></li>
276 <li><a id="btn_dar_21_9" href="#">宽屏影院(21:9)</a></li> 288 <li><a id="btn_dar_21_9" href="#">宽屏影院(21:9)</a></li>
277 - <li><a id="btn_dar_16_9" href="#">宽屏电(16:9)</a></li> 289 + <li><a id="btn_dar_16_9" href="#">宽屏电(16:9)</a></li>
278 <li><a id="btn_dar_4_3" href="#">窄屏(4:3)</a></li> 290 <li><a id="btn_dar_4_3" href="#">窄屏(4:3)</a></li>
279 <li><a id="btn_dar_fill" href="#">填充(容器比例)</a></li> 291 <li><a id="btn_dar_fill" href="#">填充(容器比例)</a></li>
280 </ul> 292 </ul>
@@ -258,8 +258,12 @@ package @@ -258,8 +258,12 @@ package
258 // TODO: FIXME: failed event. 258 // TODO: FIXME: failed event.
259 }); 259 });
260 260
261 - var streamName:String = url.substr(url.lastIndexOf("/"));  
262 - stream.play(streamName); 261 + if (url.indexOf("http") == 0) {
  262 + stream.play(url);
  263 + } else {
  264 + var streamName:String = url.substr(url.lastIndexOf("/"));
  265 + stream.play(streamName);
  266 + }
263 267
264 video = new Video(); 268 video = new Video();
265 video.width = _width; 269 video.width = _width;
@@ -274,8 +278,12 @@ package @@ -274,8 +278,12 @@ package
274 setChildIndex(video, 0); 278 setChildIndex(video, 0);
275 }); 279 });
276 280
277 - var tcUrl:String = this.url.substr(0, this.url.lastIndexOf("/"));  
278 - this.conn.connect(tcUrl); 281 + if (url.indexOf("http") == 0) {
  282 + this.conn.connect(null);
  283 + } else {
  284 + var tcUrl:String = this.url.substr(0, this.url.lastIndexOf("/"));
  285 + this.conn.connect(tcUrl);
  286 + }
279 } 287 }
280 288
281 private function on_metadata(metadata:Object):void { 289 private function on_metadata(metadata:Object):void {