mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine js for player.
This commit is contained in:
parent
0a2e00f8c5
commit
69ec66ee36
4 changed files with 92 additions and 4 deletions
|
@ -52,6 +52,68 @@ package
|
|||
|
||||
public function play(url:String):void {
|
||||
this.user_url = url;
|
||||
|
||||
this.media_conn = new NetConnection();
|
||||
this.media_conn.client = {};
|
||||
this.media_conn.client.onBWDone = function():void {};
|
||||
this.media_conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
|
||||
log("NetConnection: code=" + evt.info.code);
|
||||
|
||||
if (evt.info.hasOwnProperty("data") && evt.info.data) {
|
||||
owner.on_player_metadata(evt.info.data);
|
||||
}
|
||||
|
||||
// reject by server, maybe redirect.
|
||||
if (evt.info.code == "NetConnection.Connect.Rejected") {
|
||||
// RTMP 302 redirect.
|
||||
if (evt.info.hasOwnProperty("ex") && evt.info.ex.code == 302) {
|
||||
streamName = url.substr(url.lastIndexOf("/") + 1);
|
||||
url = evt.info.ex.redirect + "/" + streamName;
|
||||
log("Async RTMP 302 Redirect to: " + url);
|
||||
|
||||
// notify server.
|
||||
media_conn.call("Redirected", null, evt.info.ex.redirect);
|
||||
|
||||
// do 302.
|
||||
owner.on_player_302(url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: FIXME: failed event.
|
||||
if (evt.info.code != "NetConnection.Connect.Success") {
|
||||
return;
|
||||
}
|
||||
|
||||
media_stream = new NetStream(media_conn);
|
||||
media_stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
|
||||
log("NetStream: code=" + evt.info.code);
|
||||
|
||||
if (evt.info.code == "NetStream.Video.DimensionChange") {
|
||||
owner.on_player_dimension_change();
|
||||
} else if (evt.info.code == "NetStream.Buffer.Empty") {
|
||||
owner.on_player_buffer_empty();
|
||||
} else if (evt.info.code == "NetStream.Buffer.Full") {
|
||||
owner.on_player_buffer_full();
|
||||
}
|
||||
|
||||
// TODO: FIXME: failed event.
|
||||
});
|
||||
|
||||
// setup stream before play.
|
||||
owner.on_player_before_play();
|
||||
|
||||
if (url.indexOf("http") == 0) {
|
||||
media_stream.play(url);
|
||||
} else {
|
||||
streamName = url.substr(url.lastIndexOf("/") + 1);
|
||||
media_stream.play(streamName);
|
||||
}
|
||||
|
||||
owner.on_player_play();
|
||||
});
|
||||
|
||||
this.media_conn.connect(null);
|
||||
}
|
||||
|
||||
public function close():void {
|
||||
|
|
|
@ -14,13 +14,19 @@ package
|
|||
public static var logData:String = "";
|
||||
|
||||
/**
|
||||
* initialize the player by flashvars for config.
|
||||
* @param flashvars the config.
|
||||
* whether string s endswith f.
|
||||
*/
|
||||
public static function stringEndswith(s:String, f:String):Boolean {
|
||||
return s && f && s.indexOf(f) == s.length - f.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether string s startswith f.
|
||||
*/
|
||||
public static function stringStartswith(s:String, f:String):Boolean {
|
||||
return s && f && s.indexOf(f) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* write log to trace and console.log.
|
||||
* @param msg the log message.
|
||||
|
|
|
@ -429,7 +429,7 @@ package
|
|||
js_call_stop();
|
||||
|
||||
// create player.
|
||||
if (Utility.stringEndswith(url, ".m3u8")) {
|
||||
if (Utility.stringEndswith(url, ".m3u8") && Utility.stringStartswith(url, "http://")) {
|
||||
player = new M3u8Player(this);
|
||||
log("create M3U8 player.");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue