mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
for #5114, display metadata.
This commit is contained in:
parent
a8ee3162d4
commit
82aa9d120c
6 changed files with 258 additions and 121 deletions
|
@ -5,7 +5,7 @@
|
|||
* depends: jquery1.10
|
||||
* https://code.csdn.net/snippets/147103
|
||||
* @see: http://blog.csdn.net/win_lin/article/details/17994347
|
||||
* v 1.0.11
|
||||
* v 1.0.14
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -96,19 +96,76 @@ function system_array_get(arr, elem_or_function) {
|
|||
/**
|
||||
* to iterate on array.
|
||||
* @param arr the array to iterate on.
|
||||
* @param pfn the function to apply on it
|
||||
* @param pfn the function to apply on it. return false to break loop.
|
||||
* for example,
|
||||
* arr = [10, 15, 20, 30, 20, 40]
|
||||
* system_array_foreach(arr, function(elem, index){
|
||||
* console.log('index=' + index + ',elem=' + elem);
|
||||
* });
|
||||
* @return true when iterate all elems.
|
||||
*/
|
||||
function system_array_foreach(arr, pfn) {
|
||||
if (!pfn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (pfn) {
|
||||
pfn(arr[i], i)
|
||||
if (!pfn(arr[i], i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether the str starts with flag.
|
||||
*/
|
||||
function system_string_startswith(str, flag) {
|
||||
if (typeof flag == "object" && flag.constructor == Array) {
|
||||
for (var i = 0; i < flag.length; i++) {
|
||||
if (system_string_startswith(str, flag[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str && flag && str.length >= flag.length && str.indexOf(flag) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether the str ends with flag.
|
||||
*/
|
||||
function system_string_endswith(str, flag) {
|
||||
if (typeof flag == "object" && flag.constructor == Array) {
|
||||
for (var i = 0; i < flag.length; i++) {
|
||||
if (system_string_endswith(str, flag[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str && flag && str.length >= flag.length && str.indexOf(flag) == str.length - flag.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* trim the start and end of flag in str.
|
||||
* @param flag a string to trim.
|
||||
*/
|
||||
function system_string_trim(str, flag) {
|
||||
if (!flag || !flag.length || typeof flag != "string") {
|
||||
return str;
|
||||
}
|
||||
|
||||
while (system_string_startswith(str, flag)) {
|
||||
str = str.substr(flag.length);
|
||||
}
|
||||
|
||||
while (system_string_endswith(str, flag)) {
|
||||
str = str.substr(0, str.length - flag.length);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,12 +243,19 @@ function parse_query_string(){
|
|||
}
|
||||
}
|
||||
|
||||
// split again for angularjs.
|
||||
if (query_string.indexOf("?") > 0) {
|
||||
query_string = query_string.split("?")[1];
|
||||
}
|
||||
|
||||
var queries = query_string.split("&");
|
||||
$(queries).each(function(){
|
||||
var query = this.split("=");
|
||||
for (var i = 0; i < queries.length; i++) {
|
||||
var elem = queries[i];
|
||||
|
||||
var query = elem.split("=");
|
||||
obj[query[0]] = query[1];
|
||||
obj.user_query[query[0]] = query[1];
|
||||
});
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -244,6 +308,8 @@ function parse_rtmp_url(rtmp_url) {
|
|||
}
|
||||
|
||||
var ret = {
|
||||
url: rtmp_url,
|
||||
schema: a.protocol.replace(":", ""),
|
||||
server: a.hostname, port: port,
|
||||
vhost: vhost, app: app, stream: stream
|
||||
};
|
||||
|
@ -500,7 +566,14 @@ AsyncRefresh2.prototype.initialize = function(pfn, timeout) {
|
|||
* stop refresh, the refresh pfn is set to null.
|
||||
*/
|
||||
AsyncRefresh2.prototype.stop = function() {
|
||||
this.refresh_change(null, null);
|
||||
this.__call.__enabled = false;
|
||||
}
|
||||
/**
|
||||
* restart refresh, use previous config.
|
||||
*/
|
||||
AsyncRefresh2.prototype.restart = function() {
|
||||
this.__call.__enabled = true;
|
||||
this.request(0);
|
||||
}
|
||||
/**
|
||||
* change refresh pfn, the old pfn will set to disabled.
|
||||
|
|
|
@ -24,6 +24,20 @@
|
|||
<script type="text/javascript" src="js/jwplayer.js" ></script>
|
||||
<script type='text/javascript'>jwplayer.key = 'N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ=='; </script>
|
||||
<script type="text/javascript">
|
||||
/****
|
||||
* The parameters for this page:
|
||||
* schema, the protocol schema, rtmp or http.
|
||||
* server, the ip of the url.
|
||||
* port, the rtmp port of url.
|
||||
* vhost, the vhost of url, can equals to server.
|
||||
* app, the app of url.
|
||||
* stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
|
||||
* autostart, whether auto play the stream.
|
||||
* Additional params:
|
||||
* hls_vhost, the vhost for hls.
|
||||
* hls_port, the port for hls play.
|
||||
* hls_autostart, whether auto play the hls stream.
|
||||
*/
|
||||
var _player = null;
|
||||
var _url = null;
|
||||
$(function(){
|
||||
|
|
|
@ -384,6 +384,9 @@
|
|||
<input class="span2" style="width:135px" id="player_clock" type="text" placeholder="年-月-日 时:分:秒">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span id="debug_info"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
|
@ -466,6 +469,19 @@
|
|||
__active_mbt.addClass("active");
|
||||
}
|
||||
|
||||
/****
|
||||
* The parameters for this page:
|
||||
* schema, the protocol schema, rtmp or http.
|
||||
* server, the ip of the url.
|
||||
* port, the rtmp port of url.
|
||||
* vhost, the vhost of url, can equals to server.
|
||||
* app, the app of url.
|
||||
* stream, the stream of url, can endwith .flv or .mp4 or nothing for RTMP.
|
||||
* autostart, whether auto play the stream.
|
||||
* for example:
|
||||
* http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream&server=ossrs.net&port=1935&autostart=true&schema=rtmp
|
||||
* http://localhost:8088/players/srs_player.html?vhost=ossrs.net&app=live&stream=livestream.flv&server=ossrs.net&port=8080&autostart=true&schema=http
|
||||
*/
|
||||
$(function(){
|
||||
var query = parse_query_string();
|
||||
|
||||
|
@ -496,6 +512,9 @@
|
|||
};
|
||||
srs_player.on_player_metadata = function(metadata) {
|
||||
$("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")");
|
||||
if (metadata.ip && metadata.pid && metadata.cid) {
|
||||
$("#debug_info").text("DEBUG: " + metadata.ip + ' grep -in "\\[' + metadata.pid + '\\]\\[' + metadata.cid + '\\]"');
|
||||
}
|
||||
select_dar("#btn_dar_original", 0, 0);
|
||||
select_fs_size("#btn_fs_size_screen_100", "screen", 100);
|
||||
};
|
||||
|
@ -551,6 +570,9 @@
|
|||
+ "vhost=" + rtmp.vhost + "&app=" + rtmp.app + "&stream=" + rtmp.stream
|
||||
+ "&server=" + rtmp.server + "&port=" + rtmp.port
|
||||
+ "&autostart=true";
|
||||
if (rtmp.schema == "http") {
|
||||
url += "&schema=http";
|
||||
}
|
||||
$("#player_url").text($("#txt_url").val()).attr("href", url);
|
||||
|
||||
$("#link_server").text(rtmp.server);
|
||||
|
|
|
@ -39,3 +39,4 @@
|
|||
<flashCatalyst validateFlashCatalystCompatibility="false"/>
|
||||
</actionScriptProperties>
|
||||
|
||||
|
||||
|
|
Binary file not shown.
|
@ -175,6 +175,11 @@ package
|
|||
private function system_on_metadata(metadata:Object):void {
|
||||
this.media_metadata = metadata;
|
||||
|
||||
// update the debug info.
|
||||
if (metadata) {
|
||||
on_debug_info(metadata);
|
||||
}
|
||||
|
||||
// for js.
|
||||
var obj:Object = __get_video_size_object();
|
||||
|
||||
|
@ -190,6 +195,21 @@ package
|
|||
if (srs_authors != null) {
|
||||
obj.contributor = srs_authors;
|
||||
}
|
||||
if (srs_id != null) {
|
||||
obj.cid = srs_id;
|
||||
}
|
||||
if (srs_pid != null) {
|
||||
obj.pid = srs_pid;
|
||||
}
|
||||
if (srs_server_ip != null) {
|
||||
obj.ip = srs_server_ip;
|
||||
}
|
||||
|
||||
var s:String = "";
|
||||
for (var key:String in obj) {
|
||||
s += key + "=" + obj[key] + " ";
|
||||
}
|
||||
log("metadata is " + s);
|
||||
|
||||
var code:int = flash.external.ExternalInterface.call(js_on_player_metadata, js_id, obj);
|
||||
if (code != 0) {
|
||||
|
@ -349,6 +369,30 @@ package
|
|||
contextMenu.customItems = customItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* server can set the debug info in _result of RTMP connect, or metadata.
|
||||
*/
|
||||
private function on_debug_info(data:*):void {
|
||||
if (data.hasOwnProperty("srs_server")) {
|
||||
srs_server = data.srs_server;
|
||||
}
|
||||
if (data.hasOwnProperty("srs_primary")) {
|
||||
srs_primary = data.srs_primary;
|
||||
}
|
||||
if (data.hasOwnProperty("srs_authors")) {
|
||||
srs_authors = data.srs_authors;
|
||||
}
|
||||
if (data.hasOwnProperty("srs_id")) {
|
||||
srs_id = data.srs_id;
|
||||
}
|
||||
if (data.hasOwnProperty("srs_pid")) {
|
||||
srs_pid = data.srs_pid;
|
||||
}
|
||||
if (data.hasOwnProperty("srs_server_ip")) {
|
||||
srs_server_ip = data.srs_server_ip;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function for js to call: to play the stream. stop then play.
|
||||
* @param url, the rtmp/http url to play.
|
||||
|
@ -375,24 +419,7 @@ package
|
|||
log("NetConnection: code=" + evt.info.code);
|
||||
|
||||
if (evt.info.hasOwnProperty("data") && evt.info.data) {
|
||||
if (evt.info.data.hasOwnProperty("srs_server")) {
|
||||
srs_server = evt.info.data.srs_server;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_primary")) {
|
||||
srs_primary = evt.info.data.srs_primary;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_authors")) {
|
||||
srs_authors = evt.info.data.srs_authors;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_id")) {
|
||||
srs_id = evt.info.data.srs_id;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_pid")) {
|
||||
srs_pid = evt.info.data.srs_pid;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_server_ip")) {
|
||||
srs_server_ip = evt.info.data.srs_server_ip;
|
||||
}
|
||||
on_debug_info(evt.info.data);
|
||||
update_context_items();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue