• JPlayer Jquery video视频插件


    近日一直在搜关于视频的jquery插件,要求功能全,跨平台,百思不得其解,偶尔找到一个插件JPlayer,国产的,很全。
    为什么选择JPlayer
    • 简单:几分钟就可以上手编码、部署
    • 可定制:可以方便地用HTML和CSS换肤
    • 轻量:压缩的mini版只有12K
    • 免费开源:没有任何许可限制
    • 社区支持:不断增长的活跃社区
    • 插件丰富:主流平台上越来越多的免费插件
    • 跨平台:跨平台跨浏览器多解码器支持
    • 文档全面:完善的文档和入门指南
    • 接口统一:提供兼容浏览器、HTML5和Flash的统一接口
    • 扩展性:拥有高扩展性的架构体系
    JPlayer支持的媒体格式
    • HTML5: mp3, mp4 (AAC/H.264), ogg (Vorbis/Theora), webm (Vorbis/VP8), wav

    • Flash: mp3, mp4 (AAC/H.264), rtmp, flv

    JPlayer支持的平台
    • Windows: Chrome, Firefox, Internet Explorer, Safari, Opera
    • Windows (legacy): IE6, IE7, IE8, IE9, IE10, IE11
    • OSX: Safari, Firefox, Chrome, Opera
    • iOS: Mobile Safari: iPad, iPhone, iPod Touch
    • Android: Android 2.3 Browser
    • Blackberry: OS 7 Phone Browser, PlayBook Browser
     
    我写了两个例子,大家一起分享一下
    第一个:播放一个视频,并且当暂停时,获取当时的视频播放进度,要求打开网页即开始播放并且播放指定位置,代码如下:
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     2 <html>
     3 <head>
     4     <meta charset="utf-8" />
     5     <title>jQuery Pagination - jPaginate</title>
     6     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     7     <link href="./skin/pink.flag/jplayer.pink.flag.css" rel="stylesheet" type="text/css" />
     8     <script type="text/javascript" src="./lib/jquery.min.js"></script>
     9     <script type="text/javascript" src="./dist/jplayer/jquery.jplayer.min.js"></script>
    10 <script type="text/javascript">
    11 //<![CDATA[
    12 $(document).ready(function(){
    13 
    14     $("#jquery_jplayer_1").jPlayer({
    15         ready: function () {
    16             $(this).jPlayer("setMedia", {
    17                 title: "Big Buck Bunny",
    18                 m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
    19                 ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
    20                 webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
    21                 poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
    22             }).jPlayer("play",10)//从10秒开始播放
    23         },
    24         swfPath: "./dist/jplayer",//当不支持html5的时候启用swf flash
    25         supplied: "webmv, ogv, m4v",
    26         size: {
    27              "640px",
    28             height: "360px",
    29             cssClass: "jp-video-360p"
    30         },
    31         useStateClassSkin: true,
    32         autoBlur: false,
    33         smoothPlayBar: true,
    34         keyEnabled: true,
    35         remainingDuration: true,
    36         toggleDuration: true,
    37         pause:function(event){
    38             //当前播放进度 %
    39             alert("currentPercentRelative="+event.jPlayer.status.currentPercentRelative);
    40             alert("currentPercentAbsolute="+event.jPlayer.status.currentPercentAbsolute);
    41             //当前播放进度 时间
    42             alert("currentTime="+event.jPlayer.status.currentTime);
    43             //alert("seekPercent="+event.jPlayer.status.seekPercent);
    44             
    45         }
    46         
    47     }).jPlayer("play").jPlayer("repeat");//自动播放 自动循环
    48 });
    49 //]]>
    50 </script>
    51 </head>
    52 <body>
    53 <div id="jp_container_1" class="jp-video jp-video-360p" role="application" aria-label="media player">
    54     <div class="jp-type-single">
    55         <div id="jquery_jplayer_1" class="jp-jplayer"></div>
    56         <div class="jp-gui">
    57             <div class="jp-video-play">
    58                 <button class="jp-video-play-icon" role="button" tabindex="0">play</button>
    59             </div>
    60             <div class="jp-interface">
    61                 <div class="jp-progress">
    62                     <div class="jp-seek-bar">
    63                         <div class="jp-play-bar"></div>
    64                     </div>
    65                 </div>
    66                 <div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div>
    67                 <div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div>
    68                 <div class="jp-details">
    69                     <div class="jp-title" aria-label="title">&nbsp;</div>
    70                 </div>
    71                 <div class="jp-controls-holder">
    72                     <div class="jp-volume-controls">
    73                         <button class="jp-mute" role="button" tabindex="0">mute</button>
    74                         <button class="jp-volume-max" role="button" tabindex="0">max volume</button>
    75                         <div class="jp-volume-bar">
    76                             <div class="jp-volume-bar-value"></div>
    77                         </div>
    78                     </div>
    79                     <div class="jp-controls">
    80                         <button class="jp-play" role="button" tabindex="0">play</button>
    81                         <button class="jp-stop" role="button" tabindex="0">stop</button>
    82                     </div>
    83                     <div class="jp-toggles">
    84                         <button class="jp-repeat" role="button" tabindex="0">repeat</button>
    85                         <button class="jp-full-screen" role="button" tabindex="0">full screen</button>
    86                     </div>
    87                 </div>
    88             </div>
    89         </div>
    90         <div class="jp-no-solution">
    91             <span>Update Required</span>
    92             To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
    93         </div>
    94     </div>
    95 </div>
    96 </body>
    97 
    98 </html>
    第二个例子 播放一个视频列表,并且指定播放列表中的某个视频的某一个点
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <!-- Website Design By: www.happyworm.com -->
    <title>Demo : jPlayer as a media playlist player</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="./skin/pink.flag/jplayer.pink.flag.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="./lib/jquery.min.js"></script>
    <script type="text/javascript" src="./dist/jplayer/jquery.jplayer.min.js"></script>
    <script type="text/javascript" src="./dist/add-on/jplayer.playlist.min.js"></script>
    <script type="text/javascript" src="./lib/json2.js"></script>
    <script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
    
        var myPlaylist = new jPlayerPlaylist({
            jPlayer: "#jquery_jplayer_1",
            cssSelectorAncestor: "#jp_container_1"
        }, [
            {
                title:"Cro Magnon Man",
                artist:"The Stark Palace",
                mp3:"http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3",
                oga:"http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg",
                poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
            },
            {
                title:"Your Face",
                artist:"The Stark Palace",
                mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
                oga:"http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg",
                poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
            },
            {
                title:"Hidden",
                artist:"Miaow",
                mp3:"http://www.jplayer.org/audio/mp3/Miaow-02-Hidden.mp3",
                oga:"http://www.jplayer.org/audio/ogg/Miaow-02-Hidden.ogg",
                poster: "http://www.jplayer.org/audio/poster/Miaow_640x360.png"
            },
            {
                title:"Big Buck Bunny Trailer",
                artist:"Blender Foundation",
                m4v:"http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
                ogv:"http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
                webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
                poster:"http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
            },
            {
                title:"Finding Nemo Teaser",
                artist:"Pixar",
                m4v: "http://www.jplayer.org/video/m4v/Finding_Nemo_Teaser.m4v",
                ogv: "http://www.jplayer.org/video/ogv/Finding_Nemo_Teaser.ogv",
                webmv: "http://www.jplayer.org/video/webm/Finding_Nemo_Teaser.webm",
                poster: "http://www.jplayer.org/video/poster/Finding_Nemo_Teaser_640x352.png"
            },
            {
                title:"Cyber Sonnet",
                artist:"The Stark Palace",
                mp3:"http://www.jplayer.org/audio/mp3/TSP-07-Cybersonnet.mp3",
                oga:"http://www.jplayer.org/audio/ogg/TSP-07-Cybersonnet.ogg",
                poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
            },
            {
                title:"Incredibles Teaser",
                artist:"Pixar",
                m4v: "http://www.jplayer.org/video/m4v/Incredibles_Teaser.m4v",
                ogv: "http://www.jplayer.org/video/ogv/Incredibles_Teaser.ogv",
                webmv: "http://www.jplayer.org/video/webm/Incredibles_Teaser.webm",
                poster: "http://www.jplayer.org/video/poster/Incredibles_Teaser_640x272.png"
            },
            {
                title:"Tempered Song",
                artist:"Miaow",
                mp3:"http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3",
                oga:"http://www.jplayer.org/audio/ogg/Miaow-01-Tempered-song.ogg",
                poster: "http://www.jplayer.org/audio/poster/Miaow_640x360.png"
            },
            {
                title:"Lentement",
                artist:"Miaow",
                mp3:"http://www.jplayer.org/audio/mp3/Miaow-03-Lentement.mp3",
                oga:"http://www.jplayer.org/audio/ogg/Miaow-03-Lentement.ogg",
                poster: "http://www.jplayer.org/audio/poster/Miaow_640x360.png"
            }
        ], {
            swfPath: "./dist/jplayer",
            supplied: "webmv, ogv, m4v, oga, mp3",
            useStateClassSkin: true,
            autoBlur: false,
            smoothPlayBar: true,
            keyEnabled: true,
            audioFullScreen: true,
            pause:function(event){
                //当前播放url
                alert("src="+event.jPlayer.status.src);
                
                alert(JSON.stringify(event.jPlayer.status.media));
                //当前播放进度 %
                alert("currentPercentRelative="+event.jPlayer.status.currentPercentRelative);
                alert("currentPercentAbsolute="+event.jPlayer.status.currentPercentAbsolute);
                //当前播放进度 时间
                alert("currentTime="+event.jPlayer.status.currentTime);
                //alert("seekPercent="+event.jPlayer.status.seekPercent);
                
            },
            ready:function(){
                $(this).jPlayer("play",20);//播放当前视频,从第20秒开始
            }    
        });
        //myPlaylist.select(2).jPlayer("play",10);
        //指定播放哪个视频
        myPlaylist.play(2);
        
    });
    //]]>
    </script>
    </head>
    <body>
    <div id="jp_container_1" class="jp-video jp-video-270p" role="application" aria-label="media player">
        <div class="jp-type-playlist">
            <div id="jquery_jplayer_1" class="jp-jplayer"></div>
            <div class="jp-gui">
                <div class="jp-video-play">
                    <button class="jp-video-play-icon" role="button" tabindex="0">play</button>
                </div>
                <div class="jp-interface">
                    <div class="jp-progress">
                        <div class="jp-seek-bar">
                            <div class="jp-play-bar"></div>
                        </div>
                    </div>
                    <div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div>
                    <div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div>
                    <div class="jp-details">
                        <div class="jp-title" aria-label="title">&nbsp;</div>
                    </div>
                    <div class="jp-controls-holder">
                        <div class="jp-volume-controls">
                            <button class="jp-mute" role="button" tabindex="0">mute</button>
                            <button class="jp-volume-max" role="button" tabindex="0">max volume</button>
                            <div class="jp-volume-bar">
                                <div class="jp-volume-bar-value"></div>
                            </div>
                        </div>
                        <div class="jp-controls">
                            <button class="jp-previous" role="button" tabindex="0">previous</button>
                            <button class="jp-play" role="button" tabindex="0">play</button>
                            <button class="jp-stop" role="button" tabindex="0">stop</button>
                            <button class="jp-next" role="button" tabindex="0">next</button>
                        </div>
                        <div class="jp-toggles">
                            <button class="jp-repeat" role="button" tabindex="0">repeat</button>
                            <button class="jp-shuffle" role="button" tabindex="0">shuffle</button>
                            <button class="jp-full-screen" role="button" tabindex="0">full screen</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="jp-playlist">
                <ul>
                    <!-- The method Playlist.displayPlaylist() uses this unordered list -->
                    <li></li>
                </ul>
            </div>
            <div class="jp-no-solution">
                <span>Update Required</span>
                To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
            </div>
        </div>
    </div>
    </body>
    
    </html>
    完成第二个例子时,要注意引用jplayer.playlist.min.js 文件,上文第二个例子将会从列表中第三个视频第20秒开始播放
  • 相关阅读:
    JDK8 Optional类使用
    Kafka RocketMQ
    Dubbo,ElasticSearch,JVM,多线程/高并发,消息中间件 常问问题
    Redis
    java jvm 虚拟机
    25 岁做什么,可在 5 年后受益匪浅?
    设计模式
    并发与并行的理解
    多线程学习
    FireFox 如何在当前页面打开书签
  • 原文地址:https://www.cnblogs.com/SK1995/p/5803057.html
Copyright © 2020-2023  润新知