winlin

add srs player

@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 $("#div_container").remove(); 21 $("#div_container").remove();
22 _player.stop(); 22 _player.stop();
23 }); 23 });
  24 +
24 $("#main_modal").on("show", function(){ 25 $("#main_modal").on("show", function(){
25 $("#div_container").remove(); 26 $("#div_container").remove();
26 27
@@ -42,6 +43,7 @@ @@ -42,6 +43,7 @@
42 }; 43 };
43 _player = jwplayer('player_id').setup(conf); 44 _player = jwplayer('player_id').setup(conf);
44 }); 45 });
  46 +
45 $("#main_modal").modal({show:true, keyboard:false}); 47 $("#main_modal").modal({show:true, keyboard:false});
46 } 48 }
47 49
@@ -14,13 +14,26 @@ @@ -14,13 +14,26 @@
14 } 14 }
15 </style> 15 </style>
16 <script type="text/javascript"> 16 <script type="text/javascript">
  17 + var srs_player = null;
  18 +
17 $(function(){ 19 $(function(){
18 // get the vhost and port to set the default url. 20 // get the vhost and port to set the default url.
19 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo 21 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
20 // url set to: rtmp://demo:1935/live/livestream 22 // url set to: rtmp://demo:1935/live/livestream
21 srs_init($("#txt_url")); 23 srs_init($("#txt_url"));
22 24
23 - var srs_player = null; 25 + $("#btn_play").click(on_btn_play);
  26 + $("#btn_pause").click(function(){
  27 + if ($("#btn_pause").text() == "暂停") {
  28 + $("#btn_pause").text("继续");
  29 + srs_player.pause();
  30 + } else {
  31 + $("#btn_pause").text("暂停");
  32 + srs_player.resume();
  33 + }
  34 + });
  35 + });
  36 + function on_btn_play(){
24 $("#main_modal").on("show", function(){ 37 $("#main_modal").on("show", function(){
25 $("#div_container").remove(); 38 $("#div_container").remove();
26 39
@@ -35,34 +48,23 @@ @@ -35,34 +48,23 @@
35 48
36 var url = $("#txt_url").val(); 49 var url = $("#txt_url").val();
37 50
38 - srs_player = new SrsPlayer("player_id", url, 530, 300); 51 + srs_player = new SrsPlayer("player_id", url, 530, 300, 0.8);
39 srs_player.on_player_ready = function() { 52 srs_player.on_player_ready = function() {
40 - // hack the callback function, start to play the url. 53 + // hack the callback function, do something then play.
41 return srs_player.play(); 54 return srs_player.play();
42 } 55 }
43 srs_player.start(); 56 srs_player.start();
44 }); 57 });
  58 +
45 $("#main_modal").on("hide", function(){ 59 $("#main_modal").on("hide", function(){
46 srs_player.stop(); 60 srs_player.stop();
47 }); 61 });
48 62
49 - $("#btn_play").click(on_btn_play);  
50 - $("#btn_pause").click(function(){  
51 - var _v = $("#btn_pause").text();  
52 - if (_v == "暂停") {  
53 - $("#btn_pause").text("继续");  
54 - srs_player.pause();  
55 - } else {  
56 - $("#btn_pause").text("暂停");  
57 - srs_player.resume();  
58 - }  
59 - });  
60 - });  
61 - function on_btn_play(){  
62 $("#main_modal").modal({show:true, keyboard:false}); 63 $("#main_modal").modal({show:true, keyboard:false});
63 } 64 }
64 65
65 - function SrsPlayer(container, stream_url, width, height) { 66 + // the SrsPlayer object.
  67 + function SrsPlayer(container, stream_url, width, height, buffer_time) {
66 if (!SrsPlayer.__id) { 68 if (!SrsPlayer.__id) {
67 SrsPlayer.__id = 100; 69 SrsPlayer.__id = 100;
68 } 70 }
@@ -76,9 +78,13 @@ @@ -76,9 +78,13 @@
76 this.stream_url = stream_url; 78 this.stream_url = stream_url;
77 this.width = width; 79 this.width = width;
78 this.height = height; 80 this.height = height;
  81 + this.buffer_time = buffer_time;
79 this.id = SrsPlayer.__id++; 82 this.id = SrsPlayer.__id++;
80 this.callbackObj = null; 83 this.callbackObj = null;
81 } 84 }
  85 + // user can set some callback, then start the player.
  86 + // callbacks:
  87 + // on_player_ready():int, when srs player ready, user can play.
82 SrsPlayer.prototype.start = function() { 88 SrsPlayer.prototype.start = function() {
83 // embed the flash. 89 // embed the flash.
84 var flashvars = {}; 90 var flashvars = {};
@@ -105,7 +111,7 @@ @@ -105,7 +111,7 @@
105 return this; 111 return this;
106 } 112 }
107 SrsPlayer.prototype.play = function() { 113 SrsPlayer.prototype.play = function() {
108 - return this.callbackObj.ref.__play(this.stream_url, this.width, this.height); 114 + return this.callbackObj.ref.__play(this.stream_url, this.width, this.height, this.buffer_time);
109 } 115 }
110 SrsPlayer.prototype.stop = function() { 116 SrsPlayer.prototype.stop = function() {
111 return this.callbackObj.ref.__stop(); 117 return this.callbackObj.ref.__stop();
@@ -104,7 +104,7 @@ package @@ -104,7 +104,7 @@ package
104 return 0; 104 return 0;
105 } 105 }
106 106
107 - public function js_call_play(url:String, _width:int, _height:int):int { 107 + public function js_call_play(url:String, _width:int, _height:int, _buffer_time:Number):int {
108 this.url = url; 108 this.url = url;
109 trace("start to play url: " + this.url); 109 trace("start to play url: " + this.url);
110 110
@@ -120,6 +120,7 @@ package @@ -120,6 +120,7 @@ package
120 } 120 }
121 121
122 stream = new NetStream(conn); 122 stream = new NetStream(conn);
  123 + stream.bufferTime = _buffer_time;
123 stream.client = {}; 124 stream.client = {};
124 stream.client.onMetaData = function(metadata:Object):void { 125 stream.client.onMetaData = function(metadata:Object):void {
125 var customItems:Array = [new ContextMenuItem("SrsPlayer")]; 126 var customItems:Array = [new ContextMenuItem("SrsPlayer")];