srs_player.html 13.3 KB
<!DOCTYPE html>
<html>
<head>
    <title>SRS</title>   
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/swfobject.js"></script>
    <script type="text/javascript" src="js/srs.js"></script>
    <style>
        body{
            padding-top: 55px;
        }
        #my_modal_footer {
            margin-top: -20px;
            padding-top: 3px;
        }
        #div_play_time {
            margin-top: 10px;
        }
        #pb_buffer_bg {
            margin-top: -4px;
            margin-bottom: 10px;
        }
    </style>
    <script type="text/javascript">
        var srs_player = null;
        
        var __active_dar = null;
        function select_dar(dar_id, num, den) {
            srs_player.dar(num, den);
            
            if (__active_dar) {
                __active_dar.removeClass("active");
            }
            
            __active_dar = $(dar_id).parent();
            __active_dar.addClass("active");
        }
        
        var __active_size = null;
        function select_fs_size(size_id, refer, percent) {
            srs_player.set_fs(refer, percent);
            
            if (__active_size) {
                __active_size.removeClass("active");
            }
            
            __active_size = $(size_id).parent();
            __active_size.addClass("active");
        }
        
        var __active_bt = null;
        function select_buffer_time(bt_id, buffer_time) {
            srs_player.set_bt(buffer_time);
            
            if (__active_bt) {
                __active_bt.removeClass("active");
            }
            
            __active_bt = $(bt_id).parent();
            __active_bt.addClass("active");
        }
        
        $(function(){
            // get the vhost and port to set the default url.
            // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
            // url set to: rtmp://demo:1935/live/livestream
            srs_init("#txt_url", null, "#main_modal");
            
            $("#fs_tips").tooltip({
                title: "点击视频进入或退出全屏"
            });
            
            $("#main_modal").on("show", function(){
                if (srs_player) {
                    return;
                }
                
                $("#div_container").remove();
                
                var obj = $("<div/>");
                $(obj).attr("id", "div_container");
                
                var player = $("<div/>");
                $(obj).append(player);
                $(obj).attr("id", "player_id");
                
                $("#player").append(obj);
                
                var url = $("#txt_url").val();
                
                srs_player = new SrsPlayer("player_id", url, 
                    srs_get_player_width(), srs_get_player_height());
                srs_player.on_player_ready = function() {
                    select_buffer_time("#btn_bt_0_8", 0.8);
                    srs_player.play();
                }
                srs_player.on_player_metadata = function(metadata) {
                    $("#btn_dar_original").text("视频原始比例" + "(" + metadata.width + ":" + metadata.height + ")");
                    select_dar("#btn_dar_original", 0, 0);
                    select_fs_size("#btn_fs_size_screen_100", "screen", 100);
                }
                srs_player.on_player_timer = function(time, buffer_length) {
                    var buffer = buffer_length / srs_player.buffer_time * 100;
                    $("#pb_buffer").width(Number(buffer).toFixed(1) + "%");
                    
                    $("#pb_buffer_bg").attr("title", 
                        "缓冲区长度:" + Number(buffer_length).toFixed(1) + "秒(" 
                        + Number(buffer).toFixed(1) + "%)");
                    
                    var time_str = "";
                    // day
                    time_str = padding(parseInt(time / 24 / 3600), 2, '0') + " ";
                    // hour
                    time = time % (24 * 3600);
                    time_str += padding(parseInt(time / 3600), 2, '0') + ":";
                    // minute
                    time = time % (3600);
                    time_str += padding(parseInt(time / 60), 2, '0') + ":";
                    // seconds
                    time = time % (60);
                    time_str += padding(parseInt(time), 2, '0');
                    // show
                    $("#txt_time").val(time_str);
                }
                srs_player.start();
            });
            
            $("#main_modal").on("hide", function(){
                if ($("#main_modal").is(":visible")) {
                    return;
                }
                
                if (srs_player) {
                    srs_player.stop();
                    srs_player = null;
                }
            });
            
            $("#btn_play").click(function(){
                $("#main_modal").modal({show:true, keyboard:false});
            });
            
            $("#btn_pause").click(function(){
                if ($("#btn_pause").text() == "暂停") {
                    $("#btn_pause").text("继续");
                    srs_player.pause();
                } else {
                    $("#btn_pause").text("暂停");
                    srs_player.resume();
                }
            });
            
            if (true) {
                $("#btn_dar_original").click(function(){
                    select_dar("#btn_dar_original", 0, 0);
                });
                $("#btn_dar_21_9").click(function(){
                    select_dar("#btn_dar_21_9", 9, 21);
                });
                $("#btn_dar_16_9").click(function(){
                    select_dar("#btn_dar_16_9", 9, 16);
                });
                $("#btn_dar_4_3").click(function(){
                    select_dar("#btn_dar_4_3", 3, 4);
                });
                $("#btn_dar_fill").click(function(){
                    select_dar("#btn_dar_fill", -1, -1);
                });
            }
            
            if (true) {
                $("#btn_fs_size_video_100").click(function(){
                    select_fs_size("#btn_fs_size_video_100", "video", 100);
                });
                $("#btn_fs_size_video_75").click(function(){
                    select_fs_size("#btn_fs_size_video_75", "video", 75);
                });
                $("#btn_fs_size_video_50").click(function(){
                    select_fs_size("#btn_fs_size_video_50", "video", 50);
                });
                $("#btn_fs_size_screen_100").click(function(){
                    select_fs_size("#btn_fs_size_screen_100", "screen", 100);
                });
                $("#btn_fs_size_screen_75").click(function(){
                    select_fs_size("#btn_fs_size_screen_75", "screen", 75);
                });
                $("#btn_fs_size_screen_50").click(function(){
                    select_fs_size("#btn_fs_size_screen_50", "screen", 50);
                });
            }
            
            if (true) {
                $("#btn_bt_0_5").click(function(){
                    select_buffer_time("#btn_bt_0_5", 0.5);
                });
                $("#btn_bt_0_8").click(function(){
                    select_buffer_time("#btn_bt_0_8", 0.8);
                });
                $("#btn_bt_1").click(function(){
                    select_buffer_time("#btn_bt_1", 1);
                });
                $("#btn_bt_2").click(function(){
                    select_buffer_time("#btn_bt_2", 2);
                });
                $("#btn_bt_3").click(function(){
                    select_buffer_time("#btn_bt_3", 3);
                });
                $("#btn_bt_5").click(function(){
                    select_buffer_time("#btn_bt_5", 5);
                });
                $("#btn_bt_10").click(function(){
                    select_buffer_time("#btn_bt_10", 10);
                });
                $("#btn_bt_30").click(function(){
                    select_buffer_time("#btn_bt_30", 30);
                });
            }
        });
    </script>
</head>
<body>
<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
        <a class="brand" href="#">SRS</a>
            <div class="nav-collapse collapse">
                <ul class="nav">
                    <li class="active"><a id="nav_srs_player" href="srs_player.html">SRS播放器</a></li>
                    <li><a id="nav_srs_publisher" href="srs_publisher.html">SRS编码器</a></li>
                    <li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>
                    <li><a id="nav_jwplayer6" href="jwplayer6.html">JWPlayer6播放器</a></li>
                    <li><a id="nav_osmf" href="osmf.html">AdobeOSMF播放器</a></li>
                    <li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="alert alert-info fade in">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong><span>Usage:</span></strong> <span>输入地址后点击播放按钮</span>
    </div>
    <div class="form-inline">
        URL:
        <input type="text" id="txt_url" class="input-xxlarge" value=""></input>
        <button class="btn" id="btn_play">播放视频</button>
    </div>
    <div id="main_modal" class="modal hide fade">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3><a href="https://github.com/winlinvip/simple-rtmp-server">SrsPlayer</a></h3>
        </div>
        <div class="modal-body">
            <div id="player"></div>
            <div class="progress progress-striped active" id="pb_buffer_bg">
                <div class="bar" style="width: 0%;" id="pb_buffer"></div>
            </div>
        </div>
        <div class="modal-footer" id="my_modal_footer">
            <div class="input-prepend" id="div_play_time">
              <span class="add-on" title="播放时长">@T</span>
              <input class="span2" style="width:85px" id="txt_time" type="text" placeholder="天 时:分:秒">
            </div>
            <div class="btn-group dropup">
                <button class="btn dropdown-toggle" data-toggle="dropdown">
                    <a id="fs_tips" href="#" data-toggle="tooltip" data-placement="top" title="">
                        <img src="img/tooltip.png"/>
                    </a>
                    全屏大小<span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a id="btn_fs_size_screen_100" href="#">屏幕大小(100%)</a></li>
                    <li><a id="btn_fs_size_screen_75" href="#">屏幕大小(75%)</a></li>
                    <li><a id="btn_fs_size_screen_50" href="#">屏幕大小(50%)</a></li>
                    <li><a id="btn_fs_size_video_100" href="#">视频大小(100%)</a></li>
                    <li><a id="btn_fs_size_video_75" href="#">视频大小(75%)</a></li>
                    <li><a id="btn_fs_size_video_50" href="#">视频大小(50%)</a></li>
                </ul>
            </div>
            <div class="btn-group dropup">
                <button class="btn dropdown-toggle" data-toggle="dropdown">显示比例<span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li><a id="btn_dar_original" href="#">视频原始比例</a></li>
                    <li><a id="btn_dar_21_9" href="#">宽屏影院(21:9)</a></li>
                    <li><a id="btn_dar_16_9" href="#">宽屏电视(16:9)</a></li>
                    <li><a id="btn_dar_4_3" href="#">窄屏(4:3)</a></li>
                    <li><a id="btn_dar_fill" href="#">填充(容器比例)</a></li>
                </ul>
            </div>
            <div class="btn-group dropup">
                <button class="btn dropdown-toggle" data-toggle="dropdown">缓冲区<span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li><a id="btn_bt_0_5" href="#">0.5秒(实时)</a></li>
                    <li><a id="btn_bt_0_8" href="#">0.8秒(会议)</a></li>
                    <li><a id="btn_bt_1" href="#">1秒(低延迟)</a></li>
                    <li><a id="btn_bt_2" href="#">2秒(较低延时)</a></li>
                    <li><a id="btn_bt_3" href="#">3秒(流畅播放)</a></li>
                    <li><a id="btn_bt_5" href="#">5秒(网速较低)</a></li>
                    <li><a id="btn_bt_10" href="#">10秒(无所谓延迟)</a></li>
                    <li><a id="btn_bt_30" href="#">30秒(流畅第一)</a></li>
                </ul>
            </div>
            <div class="btn-group dropup">
                <button id="btn_pause" class="btn">暂停</button>
            </div>
            <div class="btn-group dropup">
                <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
    <hr>
    <footer>
        <p><a href="https://github.com/winlinvip/simple-rtmp-server">SRS Team &copy; 2013</a></p>
    </footer>
</div>
</body>