diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index 2694e698d..25ac12e61 100755 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -22,15 +22,15 @@ vhost __defaultVhost__ { enabled on; gop_cache on; queue_length 30; - #forward 127.0.0.1:19350; + forward 127.0.0.1:19350; hls { - enabled off; + enabled on; hls_path ./objs/nginx/html; hls_fragment 5; hls_window 30; } http_hooks { - enabled off; + enabled on; on_connect http://127.0.0.1:8085/api/v1/clients; on_close http://127.0.0.1:8085/api/v1/clients; on_publish http://127.0.0.1:8085/api/v1/streams; @@ -39,7 +39,7 @@ vhost __defaultVhost__ { on_stop http://127.0.0.1:8085/api/v1/sessions; } transcode { - enabled off; + enabled on; ffmpeg ./objs/ffmpeg/bin/ffmpeg; engine ld { enabled on; @@ -94,9 +94,9 @@ vhost dev { enabled on; gop_cache on; queue_length 10; - forward 127.0.0.1:19350; + #forward 127.0.0.1:19350; hls { - enabled on; + enabled off; hls_path ./objs/nginx/html; hls_fragment 5; hls_window 30; diff --git a/trunk/research/players/jwplayer6.html b/trunk/research/players/jwplayer6.html index f130dda4d..b87c11c0f 100755 --- a/trunk/research/players/jwplayer6.html +++ b/trunk/research/players/jwplayer6.html @@ -16,7 +16,12 @@ @@ -38,10 +153,30 @@
+
+ + Usage: 输入地址后点击播放按钮 +
+
+ URL: + + +
+
- - + \ No newline at end of file diff --git a/trunk/research/players/srs_player/release/srs_player.swf b/trunk/research/players/srs_player/release/srs_player.swf index 65fe62f45..93d6f5655 100755 Binary files a/trunk/research/players/srs_player/release/srs_player.swf and b/trunk/research/players/srs_player/release/srs_player.swf differ diff --git a/trunk/research/players/srs_player/src/srs_player.as b/trunk/research/players/srs_player/src/srs_player.as index 2598c7ad9..29d5609ab 100755 --- a/trunk/research/players/srs_player/src/srs_player.as +++ b/trunk/research/players/srs_player/src/srs_player.as @@ -1,11 +1,151 @@ package { import flash.display.Sprite; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import flash.events.Event; + import flash.events.NetStatusEvent; + import flash.external.ExternalInterface; + import flash.media.Video; + import flash.net.NetConnection; + import flash.net.NetStream; + import flash.ui.ContextMenu; + import flash.ui.ContextMenuItem; + import flash.utils.setTimeout; public class srs_player extends Sprite { + private var id:String = null; + private var on_player_ready:String = null; + + private var url:String = null; + + private var conn:NetConnection = null; + private var stream:NetStream = null; + private var video:Video = null; + public function srs_player() { + if (!this.stage) { + this.addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage); + } else { + this.onAddToStage(null); + } + } + + private function onAddToStage(evt:Event):void { + this.stage.align = StageAlign.TOP_LEFT; + this.stage.scaleMode = StageScaleMode.NO_SCALE; + + this.contextMenu = new ContextMenu(); + this.contextMenu.hideBuiltInItems(); + + var flashvars:Object = this.root.loaderInfo.parameters; + + if (!flashvars.hasOwnProperty("id")) { + throw new Error("must specifies the id"); + } + if (!flashvars.hasOwnProperty("on_player_ready")) { + throw new Error("must specifies the on_player_ready"); + } + + this.id = flashvars.id; + this.on_player_ready = flashvars.on_player_ready; + + flash.utils.setTimeout(this.onJsReady, 0); + } + + private function onJsReady():void { + if (!flash.external.ExternalInterface.available) { + trace("js not ready, try later."); + flash.utils.setTimeout(this.onJsReady, 100); + return; + } + + flash.external.ExternalInterface.addCallback("__play", this.js_call_play); + flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop); + flash.external.ExternalInterface.addCallback("__pause", this.js_call_pause); + flash.external.ExternalInterface.addCallback("__resume", this.js_call_resume); + + var code:int = flash.external.ExternalInterface.call(this.on_player_ready, this.id); + if (code != 0) { + throw new Error("callback on_player_ready failed. code=" + code); + } + } + + public function js_call_pause():int { + if (this.stream) { + this.stream.pause(); + } + return 0; + } + + public function js_call_resume():int { + if (this.stream) { + this.stream.resume(); + } + return 0; + } + + public function js_call_stop():int { + if (this.stream) { + this.stream.close(); + this.stream = null; + } + if (this.conn) { + this.conn.close(); + this.conn = null; + } + if (this.video) { + this.removeChild(this.video); + this.video = null; + } + + return 0; + } + + public function js_call_play(url:String, _width:int, _height:int):int { + this.url = url; + trace("start to play url: " + this.url); + + js_call_stop(); + + this.conn = new NetConnection(); + this.conn.client = {}; + this.conn.client.onBWDone = function():void {}; + this.conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void { + trace ("NetConnection: code=" + evt.info.code); + if (evt.info.code != "NetConnection.Connect.Success") { + return; + } + + stream = new NetStream(conn); + stream.client = {}; + stream.client.onMetaData = function(metadata:Object):void { + var customItems:Array = [new ContextMenuItem("SrsPlayer")]; + if (metadata.hasOwnProperty("server")) { + customItems.push(new ContextMenuItem("Server: " + metadata.server)); + } + if (metadata.hasOwnProperty("contributor")) { + customItems.push(new ContextMenuItem("Contributor: " + metadata.contributor)); + } + contextMenu.customItems = customItems; + }; + stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void { + trace ("NetStream: code=" + evt.info.code); + }); + stream.play(url.substr(url.lastIndexOf("/"))); + + video = new Video(); + video.width = _width; + video.height = _height; + video.attachNetStream(stream); + video.smoothing = true; + addChild(video); + }); + this.conn.connect(this.url.substr(0, this.url.lastIndexOf("/"))); + + return 0; } } } \ No newline at end of file