diff --git a/trunk/research/players/js/srs.js b/trunk/research/players/js/srs.js index 91f0e6b58..3ca36107a 100755 --- a/trunk/research/players/js/srs.js +++ b/trunk/research/players/js/srs.js @@ -401,13 +401,18 @@ function SrsPublisher(container, width, height) { this.code = 0; // error code defines. - this.error_device_muted = 100; + this.errors = { + "100": "无法获取指定的摄像头", //error_camera_get + "101": "无法获取指定的麦克风", //error_microphone_get + "102": "摄像头为禁用状态,推流时请允许flash访问摄像头", //error_camera_muted + }; } /** * user can set some callback, then start the publisher. * callbacks: * on_publisher_ready(cameras, microphones):int, when srs publisher ready, user can publish. -* on_publisher_error(code):int, when srs publisher error, callback this method. +* on_publisher_error(code, desc):int, when srs publisher error, callback this method. +* on_publisher_warn(code, desc):int, when srs publisher warn, callback this method. */ SrsPublisher.prototype.start = function() { // embed the flash. @@ -415,6 +420,7 @@ SrsPublisher.prototype.start = function() { flashvars.id = this.id; flashvars.on_publisher_ready = "__srs_on_publisher_ready"; flashvars.on_publisher_error = "__srs_on_publisher_error"; + flashvars.on_publisher_warn = "__srs_on_publisher_warn"; var params = {}; params.wmode = "opaque"; @@ -464,9 +470,13 @@ SrsPublisher.prototype.on_publisher_ready = function(cameras, microphones) { /** * when publisher error. * @code the error code. +* @desc the error desc message. */ -SrsPublisher.prototype.on_publisher_error = function(code) { - throw new Error("publisher error. code=" + code); +SrsPublisher.prototype.on_publisher_error = function(code, desc) { + throw new Error("publisher error. code=" + code + ", desc=" + desc); +} +SrsPublisher.prototype.on_publisher_warn = function(code, desc) { + throw new Error("publisher warn. code=" + code + ", desc=" + desc); } function __srs_find_publisher(id) { for (var i = 0; i < SrsPublisher.__publishers.length; i++) { @@ -494,6 +504,13 @@ function __srs_on_publisher_error(id, code) { publisher.code = code; - publisher.on_publisher_error(code); + publisher.on_publisher_error(code, publisher.errors[""+code]); +} +function __srs_on_publisher_warn(id, code) { + var publisher = __srs_find_publisher(id); + + publisher.code = code; + + publisher.on_publisher_warn(code, publisher.errors[""+code]); } diff --git a/trunk/research/players/srs_player/release/srs_player.swf b/trunk/research/players/srs_player/release/srs_player.swf index dfea703f0..d129187e3 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_publisher.html b/trunk/research/players/srs_publisher.html index eee8c6c50..8d9d5c937 100755 --- a/trunk/research/players/srs_publisher.html +++ b/trunk/research/players/srs_publisher.html @@ -115,30 +115,33 @@ } $("#sl_bitrate option[value='350']").attr("selected", true); }; - srs_publisher.on_publisher_error = function(code) { - if (code == srs_publisher.error_device_muted) { - error(code, "摄像头和麦克风被禁用,请右键flash播放器启用。"); - } else { - error(code, "未知系统错误"); - } + srs_publisher.on_publisher_error = function(code, desc) { + error(code, desc); }; - srs_publisher.start(); - - // start the normal player with HLS supported. - remote_player = new SrsPlayer("remote_player", 430, 185); - remote_player.on_player_ready = function() { - remote_player.set_bt(0.8); - remote_player.set_fs("screen", 100); + srs_publisher.on_publisher_warn = function(code, desc) { + warn(code, desc); }; - remote_player.start(); + srs_publisher.start(); - // start the realtime player. - realtime_player = new SrsPlayer("realtime_player", 430, 185); - realtime_player.on_player_ready = function() { - realtime_player.set_bt(0.8); - realtime_player.set_fs("screen", 100); - }; - realtime_player.start(); + // if no play specified, donot show the player, for debug the publisher. + var query = parse_query_string(); + if (query.no_play != "true") { + // start the normal player with HLS supported. + remote_player = new SrsPlayer("remote_player", 430, 185); + remote_player.on_player_ready = function() { + remote_player.set_bt(0.8); + remote_player.set_fs("screen", 100); + }; + remote_player.start(); + + // start the realtime player. + realtime_player = new SrsPlayer("realtime_player", 430, 185); + realtime_player.on_player_ready = function() { + realtime_player.set_bt(0.8); + realtime_player.set_fs("screen", 100); + }; + realtime_player.start(); + } }); /** @@ -209,28 +212,37 @@ info("开始推流到服务器"); srs_publisher.publish(url, vcodec, acodec); - // directly play the url for the realtime player. - realtime_player.stop(); - realtime_player.play(url); + if (realtime_player) { + // directly play the url for the realtime player. + realtime_player.stop(); + realtime_player.play(url); + } - // the normal player should play the transcoded stream in another vhost. - // for example, publish stream to vhost players, - // the realtime player play the vhost players, which may donot support HLS, - // the normal player play the vhost players_pub, which transcoded to h264/aac with HLS. - var ret = srs_parse_rtmp_url(url); - var pub_url = "rtmp://" + ret.server + ":" + ret.port + "/" + ret.app; - pub_url += "?vhost=" + srs_get_player_publish_vhost(ret.vhost) + "/" + ret.stream; - remote_player.stop(); - remote_player.play(pub_url); + if (remote_player) { + // the normal player should play the transcoded stream in another vhost. + // for example, publish stream to vhost players, + // the realtime player play the vhost players, which may donot support HLS, + // the normal player play the vhost players_pub, which transcoded to h264/aac with HLS. + var ret = srs_parse_rtmp_url(url); + var pub_url = "rtmp://" + ret.server + ":" + ret.port + "/" + ret.app; + pub_url += "?vhost=" + srs_get_player_publish_vhost(ret.vhost) + "/" + ret.stream; + remote_player.stop(); + remote_player.play(pub_url); + } } function info(desc) { - $("#txt_log").removeClass("alert-error").addClass("alert-info"); + $("#txt_log").addClass("alert-info").removeClass("alert-error").removeClass("alert-warn"); $("#txt_log_title").text("Info:"); $("#txt_log_msg").text(desc); } + function warn(code, desc) { + $("#txt_log").removeClass("alert-info").removeClass("alert-error").addClass("alert-warn"); + $("#txt_log_title").text("Warn:"); + $("#txt_log_msg").text("code: " + code + ", " + desc); + } function error(code, desc) { - $("#txt_log").removeClass("alert-info").addClass("alert-error"); + $("#txt_log").removeClass("alert-info").addClass("alert-error").removeClass("alert-warn"); $("#txt_log_title").text("Error:"); $("#txt_log_msg").text("code: " + code + ", " + desc); } @@ -258,7 +270,7 @@