歌曲播放我们会发现他的兼容性不是很好,譬如IE上能播放的flash播放器,再firfox或者chrome上就不是很好的应用了,因为有插件的阻碍!HTML5的出现让这一切成为了可能,但是播放器虽然播放了,我们还要关注一下用户的体验度,所以,我们就写了一个HTML兼容的播放器!向下兼容IE6-9、chrome、firfox、opera等主流播放器,应该是全兼容!实现原理代码给大家奉上!
005 | < title >歌词同步播放器-powered by widuu xiaowei</ title > |
006 | < meta http-equiv = "Cache-Control" content = "no-cache" > |
007 | < meta name = "viewport" content = "width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.4" > |
008 | < meta name = "MobileOptimized" content = "240" > |
009 | < link href = "/mp3/css/blue.css" rel = "stylesheet" type = "text/css" /> |
010 | < script type = "text/javascript" src = "/mp3/js/jquery.js" ></ script > |
011 | < script type = "text/javascript" src = "/mp3/js/jquery.jplayer.js" ></ script > |
012 | < script type = "text/javascript" src = "/mp3/js/lrc.js" ></ script > |
013 | < style type = "text/css" > |
014 | * { margin:0; padding:0; } |
015 | ul, ol, dl { list-style:none; } |
016 | .content li.hover{ color:red; } |
017 | .content{ width:402px; height:200px; background:#ccc; overflow:hidden; padding:10px;} |
021 | $(document).ready(function(){ |
022 | $("#jquery_jplayer_1").jPlayer({ |
023 | ready: function (event) { |
024 | $(this).jPlayer("setMedia", { |
025 | mp3:"yangcong.mp3" //mp3的播放地址 |
028 | timeupdate: function(event) { |
029 | if(event.jPlayer.status.currentTime==0){ |
032 | time = event.jPlayer.status.currentTime; |
036 | play: function(event) { |
037 | //点击开始方法调用lrc。start歌词方法 返回时间time |
039 | if(event.jPlayer.status.currentTime==0){ |
040 | $("#jquery_jplayer_1").jPlayer("pause",1); |
043 | if($('#lrc_content').val()!==""){ |
044 | $.lrc.start($('#lrc_content').val(), function() { |
048 | $(".content").html("没有字幕"); |
051 | repeat: function(event) { |
052 | if(event.jPlayer.options.loop) { |
053 | $(this).unbind(".jPlayerRepeat").bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() { |
054 | $(this).jPlayer("play"); |
057 | $(this).unbind(".jPlayerRepeat"); |
060 | swfPath: "/js", //存放jplayer.swf的决定路径 |
061 | solution:"html, flash", //支持的页面 |
062 | supplied: "mp3", //支持的音频的格式 |
066 | $("#lrc_content").hide(); |
072 | < textarea id = "lrc_content" name = "textfield" cols = "70" rows = "10" > |
077 | [00:11.38]如果你眼神能够为我片刻的降临 |
079 | [00:28.88]盘底的洋葱像我永远是配角戏 |
080 | [00:35.74]偷偷的看着你偷偷的隐藏着自己 |
085 | [00:56.40]你是我最压抑最深处的秘密 |
089 | [01:11.60]只要你能听到我看到我的全心全意 |
094 | [01:30.41]你是我最压抑最深处的秘密 |
098 | [01:45.15]只要你能听到我看到我的全心全意 |
101 | [01:59.84]只要你能听到我看到我的全心全意 |
108 | < div id = "jquery_jplayer_1" class = "jp-jplayer" ></ div > |
110 | < div id = "jp_container_1" class = "jp-audio" > |
111 | < div class = "jp-type-single" > |
112 | < div class = "jp-gui jp-interface" > |
113 | < ul class = "jp-controls" > |
114 | < li >< a href = "javascript:;" class = "jp-play" tabindex = "1" >play</ a ></ li > |
115 | < li >< a href = "javascript:;" class = "jp-pause" tabindex = "1" >pause</ a ></ li > |
116 | < li >< a href = "javascript:;" class = "jp-stop" tabindex = "1" >stop</ a ></ li > |
117 | < li >< a href = "javascript:;" class = "jp-mute" tabindex = "1" title = "mute" >mute</ a ></ li > |
118 | < li >< a href = "javascript:;" class = "jp-unmute" tabindex = "1" title = "unmute" >unmute</ a ></ li > |
119 | < li >< a href = "javascript:;" class = "jp-volume-max" tabindex = "1" title = "max volume" >max volume</ a ></ li > |
121 | < div class = "jp-progress" > |
122 | < div class = "jp-seek-bar" > |
123 | < div class = "jp-play-bar" ></ div > |
126 | < div class = "jp-volume-bar" > |
127 | < div class = "jp-volume-bar-value" ></ div > |
129 | < div class = "jp-time-holder" > |
130 | < div class = "jp-current-time" ></ div > |
131 | < div class = "jp-duration" ></ div > |
133 | < ul class = "jp-toggles" > |
134 | < li >< a href = "javascript:;" class = "jp-repeat" tabindex = "1" title = "repeat" >repeat</ a ></ li > |
135 | < li >< a href = "javascript:;" class = "jp-repeat-off" tabindex = "1" title = "repeat off" >repeat off</ a ></ li > |
139 | < div class = "jp-title" > |
141 | < li >mp3player powered by xiaowei</ li > |
144 | < div class = "jp-no-solution" > |
145 | < span >Update Required</ span > |
146 | 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 >. |
150 | < div class = "content" >< ul id = "lrc_list" > |
剩下的就是我的组件了,大家可以下载一下!http://pan.baidu.com/share/link?shareid=225514&uk=3172762343这是下载地址哈!
如果您有什么不明白的,可以联系我,如果您还有什么需求也可以联系我,发现bug改进的地方也可以联系我谢谢!