1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

add srs player

This commit is contained in:
winlin 2013-12-20 00:26:34 +08:00
parent 40c1298476
commit 5bfb561f89
4 changed files with 28 additions and 19 deletions

View file

@ -21,6 +21,7 @@
$("#div_container").remove(); $("#div_container").remove();
_player.stop(); _player.stop();
}); });
$("#main_modal").on("show", function(){ $("#main_modal").on("show", function(){
$("#div_container").remove(); $("#div_container").remove();
@ -42,6 +43,7 @@
}; };
_player = jwplayer('player_id').setup(conf); _player = jwplayer('player_id').setup(conf);
}); });
$("#main_modal").modal({show:true, keyboard:false}); $("#main_modal").modal({show:true, keyboard:false});
} }

View file

@ -14,13 +14,26 @@
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
var srs_player = null;
$(function(){ $(function(){
// get the vhost and port to set the default url. // get the vhost and port to set the default url.
// for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
// url set to: rtmp://demo:1935/live/livestream // url set to: rtmp://demo:1935/live/livestream
srs_init($("#txt_url")); srs_init($("#txt_url"));
var srs_player = null; $("#btn_play").click(on_btn_play);
$("#btn_pause").click(function(){
if ($("#btn_pause").text() == "暂停") {
$("#btn_pause").text("继续");
srs_player.pause();
} else {
$("#btn_pause").text("暂停");
srs_player.resume();
}
});
});
function on_btn_play(){
$("#main_modal").on("show", function(){ $("#main_modal").on("show", function(){
$("#div_container").remove(); $("#div_container").remove();
@ -35,34 +48,23 @@
var url = $("#txt_url").val(); var url = $("#txt_url").val();
srs_player = new SrsPlayer("player_id", url, 530, 300); srs_player = new SrsPlayer("player_id", url, 530, 300, 0.8);
srs_player.on_player_ready = function() { srs_player.on_player_ready = function() {
// hack the callback function, start to play the url. // hack the callback function, do something then play.
return srs_player.play(); return srs_player.play();
} }
srs_player.start(); srs_player.start();
}); });
$("#main_modal").on("hide", function(){ $("#main_modal").on("hide", function(){
srs_player.stop(); srs_player.stop();
}); });
$("#btn_play").click(on_btn_play);
$("#btn_pause").click(function(){
var _v = $("#btn_pause").text();
if (_v == "暂停") {
$("#btn_pause").text("继续");
srs_player.pause();
} else {
$("#btn_pause").text("暂停");
srs_player.resume();
}
});
});
function on_btn_play(){
$("#main_modal").modal({show:true, keyboard:false}); $("#main_modal").modal({show:true, keyboard:false});
} }
function SrsPlayer(container, stream_url, width, height) { // the SrsPlayer object.
function SrsPlayer(container, stream_url, width, height, buffer_time) {
if (!SrsPlayer.__id) { if (!SrsPlayer.__id) {
SrsPlayer.__id = 100; SrsPlayer.__id = 100;
} }
@ -76,9 +78,13 @@
this.stream_url = stream_url; this.stream_url = stream_url;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.buffer_time = buffer_time;
this.id = SrsPlayer.__id++; this.id = SrsPlayer.__id++;
this.callbackObj = null; this.callbackObj = null;
} }
// user can set some callback, then start the player.
// callbacks:
// on_player_ready():int, when srs player ready, user can play.
SrsPlayer.prototype.start = function() { SrsPlayer.prototype.start = function() {
// embed the flash. // embed the flash.
var flashvars = {}; var flashvars = {};
@ -105,7 +111,7 @@
return this; return this;
} }
SrsPlayer.prototype.play = function() { SrsPlayer.prototype.play = function() {
return this.callbackObj.ref.__play(this.stream_url, this.width, this.height); return this.callbackObj.ref.__play(this.stream_url, this.width, this.height, this.buffer_time);
} }
SrsPlayer.prototype.stop = function() { SrsPlayer.prototype.stop = function() {
return this.callbackObj.ref.__stop(); return this.callbackObj.ref.__stop();

View file

@ -104,7 +104,7 @@ package
return 0; return 0;
} }
public function js_call_play(url:String, _width:int, _height:int):int { public function js_call_play(url:String, _width:int, _height:int, _buffer_time:Number):int {
this.url = url; this.url = url;
trace("start to play url: " + this.url); trace("start to play url: " + this.url);
@ -120,6 +120,7 @@ package
} }
stream = new NetStream(conn); stream = new NetStream(conn);
stream.bufferTime = _buffer_time;
stream.client = {}; stream.client = {};
stream.client.onMetaData = function(metadata:Object):void { stream.client.onMetaData = function(metadata:Object):void {
var customItems:Array = [new ContextMenuItem("SrsPlayer")]; var customItems:Array = [new ContextMenuItem("SrsPlayer")];