This commit is contained in:
212
MyPlayer/assets/js/api.js
Normal file
212
MyPlayer/assets/js/api.js
Normal file
@@ -0,0 +1,212 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'api.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me){
|
||||
var o = me.option, f = me.fn, Add = function(key, item) {
|
||||
o.apis[key] = item
|
||||
}, AddRange = function(list) {
|
||||
me.fn.each(list, Add)
|
||||
}
|
||||
o('apis', {})
|
||||
o('auto_sign', 'data-auto-play')
|
||||
AddRange({
|
||||
'虾米音乐': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.xiami.com/song/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 257
|
||||
this.attributes.height = 33
|
||||
this.attributes.src = href.replace(/.*\/(\d+)\/?/, 'http://www.xiami.com/widget/1426712_$1/singlePlayer.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'优酷视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://v.youku.com/v_show/id_')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
this.attributes.src = href.replace(/^.*id_(.*)\.html$/g, 'http://player.youku.com/player.php/sid/$1/v.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'土豆视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.tudou.com/programs/view/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
this.attributes.src = href.replace('programs\/view', 'v') + 'v.swf'
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'爱奇艺视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.iqiyi.com/v_')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
var id = href.replace(/^.*v_(.*)\.html$/g, '$1'),bind = this
|
||||
f.jsonp({
|
||||
url: me.GetPath('../../api.php'),
|
||||
data: {service: 'iqiyi', id: id},
|
||||
success: function(data) {
|
||||
if (data.url) {
|
||||
bind.attributes.src = data.url
|
||||
bind.callback()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
'音悦台MV': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://v.yinyuetai.com/video/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 334
|
||||
this.attributes.src = href.replace(/^.*\/(\d*)$/g, 'http://player.yinyuetai.com/video/player/$1/v_0.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'乐视TV': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.letv.com/ptv/vplay/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 541
|
||||
this.attributes.height = 450
|
||||
this.attributes.src = href.replace(/^.*\/(\d*)\.html$/g, 'http://i7.imgs.letv.com/player/swfPlayer.swf?autoPlay=0&id=$1')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'56视频': {
|
||||
'check': function(href) {
|
||||
return href && /http:\/\/www.56.com\/[u\d]+\/v_/.test(href)
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 408
|
||||
this.attributes.src = href.replace(/^.*\/v_(.*)\.html$/g, 'http://player.56.com/v_$id.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'哔哩哔哩': {
|
||||
'check': function(href) {
|
||||
return /http:\/\/(www\.bilibili\.com|www\.bilibili\.tv|bilibili\.kankanews\.com)?\/video\/av([0-9]+)\/(?:index_([0-9]+)\.html)?/.test(href)
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 544
|
||||
this.attributes.height = 452
|
||||
if (href.indexOf('.html') == -1) href += "/index_1.html"
|
||||
var aid = href.replace(/^.*\/av(\d+)\/.*/g, '$1'),
|
||||
page = href.replace(/^.*\/index_(\d+)\.html$/g, '$1'),
|
||||
bind = this
|
||||
this.attributes.src = 'http://static.hdslb.com//miniloader.swf?aid=' + aid + '&page=' + page
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'新浪视频': {
|
||||
'check': function(href) {
|
||||
return href && (/#\d+$/.test(href) || /^http:\/\/video\.sina\.com\.cn\/.+\d+\.html$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
var bind = this, bindWithVid = function( vid ){
|
||||
bind.base = 'flash'
|
||||
bind.attributes.width = 480
|
||||
bind.attributes.height = 370
|
||||
bind.attributes.src = 'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=' + vid + '/s.swf'
|
||||
bind.callback()
|
||||
}
|
||||
if(/#\d+$/.test(href)){
|
||||
bindWithVid( href.replace(/.+#(\d+)$/g, '$1') )
|
||||
return
|
||||
}
|
||||
f.jsonp({
|
||||
url: me.GetPath('../../api.php'),
|
||||
data: {service: 'sina', id: encodeURIComeonent(href)},
|
||||
success: function(data) {
|
||||
if (data.url) {
|
||||
bindWithVid( data.url )
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
'mp3': {
|
||||
'optional': 'type, lyrics',
|
||||
'check': function(href, type) {
|
||||
return type ? /^mp3$/.test(type) : (href && /\.(ogg|mp3)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'iframe'
|
||||
var op = {media: [], theme: f.trim(o('theme'))}
|
||||
op.media.push({
|
||||
url: href,
|
||||
title: this.element.innerHTML,
|
||||
lyrics: this.lyrics
|
||||
})
|
||||
if(this.element.getAttribute(o.auto_sign)){
|
||||
op.autoplay = true
|
||||
}
|
||||
this.attributes.src = me.GetPath('../../player/#') + JSON.stringify(op)
|
||||
this.attributes.width = 223
|
||||
this.attributes.height = 24
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'html5 audio': {
|
||||
'optional': 'type, lyrics',
|
||||
'check': function(href, type) {
|
||||
return type ? /^ogg|mp3$/.test(type) : (href && /\.(ogg|mp3)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'audio'
|
||||
this.attributes.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'html5 video': {
|
||||
'optional': 'type, width, height',
|
||||
'check': function(href, type) {
|
||||
return type ? /^ogg|mp4$/.test(type) : (href && /\.(ogv|mp4)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'video'
|
||||
this.attributs.width = this.width || 480
|
||||
this.attributs.height = this.height || 400
|
||||
this.attributes.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'flash': {
|
||||
'optional': 'type, width, height',
|
||||
'check': function(href, type) {
|
||||
return type ? /^swf$/.test(type) : (href && /\.swf$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributs.width = this.width || 480
|
||||
this.attributs.height = this.height || 400
|
||||
this.attributs.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
127
MyPlayer/assets/js/convert.js
Normal file
127
MyPlayer/assets/js/convert.js
Normal file
@@ -0,0 +1,127 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'convert.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me){
|
||||
me.Load('api.js', function(){
|
||||
var f = me.fn,
|
||||
o = me.option,
|
||||
api = me.GetPlugin('api.js')
|
||||
o('data_sign', 'data-me-sign')
|
||||
if (!o('query_parent')) {
|
||||
o.query_parent = f.qs('.post') ? '.post' : f.qs('.entry-content') ? '.entry-content' : ''
|
||||
}
|
||||
var mode = o('mode')
|
||||
o.mode = {
|
||||
ALL: mode == 'all',
|
||||
CLICK: mode == 'click',
|
||||
FIRST: mode == 'first',
|
||||
}
|
||||
var _b = {
|
||||
'flash': {
|
||||
'attributes': {
|
||||
'mimetype': 'application/x-shockwave-flash',
|
||||
'pluginspage': 'http://www.adobe.com/go/getflashplayer',
|
||||
'wmode': 'transparent',
|
||||
'quality': 'high',
|
||||
'allowFullScreen': true,
|
||||
'allowScriptAccess': 'always',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'embed'
|
||||
},
|
||||
'iframe': {
|
||||
'attributes': {
|
||||
'frameborder': '0',
|
||||
'framespacing': '0',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'iframe'
|
||||
},
|
||||
'audio': {
|
||||
'attributes': {
|
||||
'controls': 'controls',
|
||||
'autoplay': 'autoplay',
|
||||
'loop': 'loop',
|
||||
'width': 300,
|
||||
'height': 30
|
||||
},
|
||||
'tag': 'audio'
|
||||
},
|
||||
'video': {
|
||||
'attributes': {
|
||||
'controls': 'controls',
|
||||
'autoplay': 'autoplay',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'video'
|
||||
}
|
||||
}
|
||||
var Ck = me.CheckMode = function(el) {
|
||||
var data_sign = o('data_sign'),
|
||||
mode = el.getAttribute(data_sign)
|
||||
if (mode == 'false') return false
|
||||
if (mode) return mode
|
||||
f.each(api.option.apis, function(key, item) {
|
||||
if (item.check.call(el, el.href, el.getAttribute('data-type'))) {
|
||||
mode = key
|
||||
return false
|
||||
}
|
||||
})
|
||||
el.setAttribute(data_sign, mode || 'false')
|
||||
return mode
|
||||
},
|
||||
Co = me.Convert2Player = function(el) {
|
||||
var mode = Ck(el)
|
||||
if (mode) {
|
||||
var bind = {
|
||||
element: el,
|
||||
callback: callback,
|
||||
attributes: {},
|
||||
width: el.getAttribute('data-width'),
|
||||
height: el.getAttribute('data-height'),
|
||||
lyrics: el.getAttribute('data-lyrics'),
|
||||
type: el.getAttribute('data-type'),
|
||||
options: el.getAttribute('data-options'),
|
||||
}
|
||||
api.option.apis[mode].create.call(bind, el.href)
|
||||
return true
|
||||
}
|
||||
|
||||
function callback() {
|
||||
var attributes = this.attributes,
|
||||
base = _b[this.base] || {}
|
||||
f.extend(attributes, base.attributes, false)
|
||||
var swf = f.element(base.tag, attributes)
|
||||
f.after(el, swf)
|
||||
f.remove(el)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化完毕
|
||||
|
||||
|
||||
var link_list = f.qa(o.query_parent + ' a'),
|
||||
conv = o.mode.ALL || o.mode.FIRST,
|
||||
click = function(event) {
|
||||
var target = event.target,
|
||||
converted = Co(target)
|
||||
f.off(target, 'click', click)
|
||||
if (converted) event.preventDefault()
|
||||
}
|
||||
f.each(link_list, function() {
|
||||
var link = this
|
||||
if (conv) {
|
||||
var conved = Co(link)
|
||||
if (o.mode.FIRST && conved) conv = false
|
||||
} else {
|
||||
link.setAttribute(api.option.auto_sign, 'true')
|
||||
f.on(link, 'click', click)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
119
MyPlayer/assets/js/editor.js
Normal file
119
MyPlayer/assets/js/editor.js
Normal file
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'editor.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me) {
|
||||
me.Load('api.js', function(){
|
||||
var f = me.fn,
|
||||
o = me.option,
|
||||
api = me.GetPlugin('api.js'),
|
||||
apis = api.option.apis
|
||||
$(function() {
|
||||
var $wbr,
|
||||
textarea = f.id('text'),
|
||||
$textarea = $(textarea),
|
||||
md = $('input[name=markdown]').size() == 1 ,
|
||||
$button = $('<li class="wmd-button" id="wmd-myplayer-button" title="MyPlayer" ><span style="background: none; line-height: 20px;">MP</span></li>').on('click', function(event) {
|
||||
show_dialog( )
|
||||
}),
|
||||
$title = $('<input type="text" placeholder="标题" />'),
|
||||
$url = $('<input type="text" placeholder="网址" />'),
|
||||
$optional = {
|
||||
type:$('<input type="text" placeholder="格式 | 强制指定格式" />'),
|
||||
lyrics:$('<input type="text" placeholder="歌词 | 仅对音乐文件有效" />'),
|
||||
width:$('<input type="text" style="width:50%" placeholder="宽度 | 指定影像宽度" />'),
|
||||
height:$('<input type="text" style="width:50%" placeholder="高度 | 指定影像高度" />')
|
||||
},
|
||||
$ok = $('<button type="button" class="btn btn-s primary">确定</button>'),
|
||||
$cancel = $('<button type="button" class="btn btn-s">取消</button>'),
|
||||
$tip = $('<span></span>'),
|
||||
$form = $('<form>').append($title, $url, $optional.type, $optional.lyrics, $optional.width, $optional.height, $ok, $cancel, $tip),
|
||||
$dialog = $('<div class="wmd-prompt-dialog" rol="dialog" style="margin-top: -200px;">').append('<div><p><b>插入链接</b></p><p>请在下方的输入框内输入要插入的媒体页面链接。</p></div>').append($form),
|
||||
$pop = $('<div class="wmd-prompt-background" style="position: absolute; top: 0px; z-index: 1000; opacity: 0.5; height: 905px; left: 0px; width: 100%;">').add($dialog)
|
||||
var text = []
|
||||
$.each(apis,function(index){
|
||||
text.push(index)
|
||||
})
|
||||
$('div',$dialog).append($('<p>').text('目前支持的有' + text.join('、') + '等。'))
|
||||
if (md){
|
||||
insert_button()
|
||||
}else{
|
||||
$('.notice button.yes').click(function(){
|
||||
md = true
|
||||
insert_button()
|
||||
})
|
||||
$('.notice button.no').click(function(){
|
||||
md = false
|
||||
insert_button()
|
||||
})
|
||||
}
|
||||
function insert_button(){
|
||||
if (md) {
|
||||
$wbr = $('#wmd-button-row').append($('<li class="wmd-spacer wmd-spacer1" id="wmd-spacer1"></li>'))
|
||||
} else {
|
||||
$wbr = $('<ul class="wmd-button-row">').insertAfter('.url-slug')
|
||||
}
|
||||
$wbr.append($('<li class="wmd-button" id="wmd-myplayer-button" title="MyPlayer" ></li>').append($button))
|
||||
}
|
||||
|
||||
function show_dialog() {
|
||||
$('input', $pop).val('').attr('readonly',false).show()
|
||||
$tip.text('请输入有效的链接!')
|
||||
check($url.val())
|
||||
$url.val('http://')
|
||||
$cancel.click(function(){
|
||||
$pop.remove()
|
||||
}),
|
||||
$ok.click(function(){
|
||||
write()
|
||||
$cancel.click()
|
||||
})
|
||||
$url.keyup(onkeyup)
|
||||
$optional.type.keyup(onkeyup)
|
||||
$title.val($textarea.getSelection().text)
|
||||
$pop.appendTo(document.body)
|
||||
}
|
||||
var mode = {}, time
|
||||
function onkeyup(){
|
||||
clearTimeout(time)
|
||||
time = setTimeout(function(){
|
||||
mode.key = check($url.val(), $optional.type.val())
|
||||
$tip.text(mode.key ? '将启用 ' + mode.key + ' 播放器!' : '这是不认识的链接!')
|
||||
f.each($optional, function(key, $input){
|
||||
if( !mode.key || (apis[mode.key].optional && apis[mode.key].optional.indexOf(key)>-1) ) {
|
||||
$input.attr('readonly',false).show()
|
||||
mode[key] = true
|
||||
} else{
|
||||
$input.attr('readonly',true).hide()
|
||||
mode[key] = false
|
||||
}
|
||||
})
|
||||
}, 100);
|
||||
}
|
||||
function check(href, type) {
|
||||
var result = false
|
||||
f.each(apis, function(key, api) {
|
||||
if (api.check.call(null, href, type)) {
|
||||
result = key
|
||||
return false
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
function write() {
|
||||
var sel = $textarea.getSelection(), end,
|
||||
html = '<a href="' + $url.val() + '"'
|
||||
if(mode && mode['type'] && $optional.type.val()) html += ' data-type="' + $optional.type.val() + '"'
|
||||
if(mode && mode['lyrics'] && $optional.lyrics.val()) html += ' data-lyrics="' + $optional.lyrics.val() + '"'
|
||||
if(mode && mode['width'] && $optional.width.val()) html += ' data-width="' + $optional.width.val() + '"'
|
||||
if(mode && mode['height'] && $optional.height.val()) html += ' data-height="' + $optional.height.val() + '"'
|
||||
html += '>' + $title.val() + '</a>'
|
||||
end = (sel ? sel.start : 0) + html.length
|
||||
$textarea.replaceSelection(html)
|
||||
$textarea.setSelection(end, end)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
1
MyPlayer/assets/js/perichr.js
Normal file
1
MyPlayer/assets/js/perichr.js
Normal file
File diff suppressed because one or more lines are too long
211
MyPlayer/assets/js/player.js
Normal file
211
MyPlayer/assets/js/player.js
Normal file
@@ -0,0 +1,211 @@
|
||||
'use strict';
|
||||
//MyPlayer 播放页面
|
||||
(function(root, doc, $, undefined){
|
||||
var defaultOptions = {media:[],front:'white',background:'orange',actived:'red'},
|
||||
$jplayer, $player, $list, $state, $title, $progress, $lyric, options = {}, current = -1, length, first = true
|
||||
$(function(){
|
||||
getOptions()
|
||||
length = options.media.length
|
||||
init()
|
||||
setTheme(options)
|
||||
if(options.media && length > 0 ){
|
||||
if(length>1){
|
||||
$('body').append($list)
|
||||
}
|
||||
next()
|
||||
}
|
||||
})
|
||||
function next(){
|
||||
if(current == length -1 ){
|
||||
current = -1
|
||||
}
|
||||
load(options.media[++current])
|
||||
}
|
||||
function setTheme(){
|
||||
if(options.front){
|
||||
$player.css('color',options.front)
|
||||
$state.css({
|
||||
'border-left-color':options.front,
|
||||
'border-right-color':options.front
|
||||
})
|
||||
}
|
||||
if(options.background){
|
||||
$player.css('background-color',options.background)
|
||||
}
|
||||
if(options.actived){
|
||||
$progress.css('background-color',options.actived)
|
||||
}
|
||||
}
|
||||
function loading(text){
|
||||
$title.text(text)
|
||||
$player.attr('title',text)
|
||||
doc.title = text
|
||||
}
|
||||
function load(media){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('destroy')
|
||||
$jplayer.unbind().empty().remove()
|
||||
$jplayer = null
|
||||
}
|
||||
if(media.url){
|
||||
setNewMedia(media)
|
||||
}else if(media.xiami){
|
||||
loading('正在尝试载入虾米音乐……')
|
||||
$.ajax({
|
||||
url: '../api.php',
|
||||
data:{service: 'xiami',id: media.xiami},
|
||||
type: 'GET',
|
||||
dataType: 'jsonp',
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if(data[0]){
|
||||
data = data[0]
|
||||
media.url = data.url
|
||||
media.title = data.title
|
||||
media.artist = data.artist
|
||||
media.lyric = data.lyric_url
|
||||
setNewMedia(media)
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
options.media.splice(current,1)
|
||||
length--
|
||||
current--
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function getType(url){
|
||||
var index = url.indexOf('?')
|
||||
if(index>0){
|
||||
url = url.substring(0,index)
|
||||
}
|
||||
index = url.lastIndexOf('.')
|
||||
return url.substring(index+1)
|
||||
}
|
||||
function parseLyric(text){
|
||||
text = text.split('\r\n')
|
||||
var lyric = []
|
||||
$.each(text, function(index, value){
|
||||
value = $.trim(value)
|
||||
var d = value.match(/^\[\d{2}:\d{2}((\.|\:)\d{2})\]/g)
|
||||
if(!d) return
|
||||
var dt = String(d).split(':')
|
||||
var t = value.split(d)
|
||||
var _t = Math.round(parseInt(dt[0].split('[')[1])*60+parseFloat(dt[1].split(']')[0])*100)/100
|
||||
lyric.push([_t, t[1]])
|
||||
})
|
||||
return lyric
|
||||
}
|
||||
function setNewMedia(media){
|
||||
media.type = media.type || getType( media.url ) || 'mp3'
|
||||
$jplayer = $('<div>').appendTo($player).attr('id','jplayer')
|
||||
.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
$progress.width(Math.round(e.jPlayer.status.currentPercentAbsolute / 100 * $player.width()))
|
||||
})
|
||||
.jPlayer({
|
||||
ready:function(){
|
||||
$title.text(media.title + (media.artist? ' by ' + media.artist : ''))
|
||||
$player.attr('title',media.title)
|
||||
doc.title = media.title
|
||||
var obj ={}
|
||||
obj[media.type] = media.url
|
||||
$jplayer.jPlayer('setMedia', obj)
|
||||
if(!first || options.autoplay){
|
||||
play()
|
||||
first = false
|
||||
}
|
||||
},
|
||||
ended:function(){
|
||||
$progress.width('0')
|
||||
if(length == 1){
|
||||
play()
|
||||
}else{
|
||||
next()
|
||||
}
|
||||
},
|
||||
consoleAlerts:true,
|
||||
preload: 'none',
|
||||
swfPath: '../assets/swf/'
|
||||
,supplied: media.type
|
||||
})
|
||||
if(media.lyric){
|
||||
$.ajax({
|
||||
url: '../api.php',
|
||||
data:{service: 'lyric', url: media.lyric},
|
||||
type: 'GET',
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if(data && data.source){
|
||||
data = parseLyric(data.source)
|
||||
$jplayer.jPlayer.hasLyric = true
|
||||
var m = 0
|
||||
$jplayer.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
if(e.jPlayer.status.currentTime < 0.5){
|
||||
m = 0
|
||||
}
|
||||
if ( m < data.length && e.jPlayer.status.currentTime > data[m][0]){
|
||||
$lyric.text(data[m][1])
|
||||
$player.attr('title',$lyric.text())
|
||||
m++
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function getOptions(){
|
||||
options = $.extend(options, defaultOptions)
|
||||
try{
|
||||
$.extend(options, JSON.parse(document.location.hash.replace(/^#/,'')))
|
||||
}catch(e){
|
||||
}
|
||||
options.theme=options.theme.split('|')
|
||||
if(options.theme[0]){
|
||||
options.front = options.theme[0]
|
||||
}
|
||||
if(options.theme[1]){
|
||||
options.background = options.theme[1]
|
||||
}
|
||||
if(options.theme[2]){
|
||||
options.actived = options.theme[2]
|
||||
}
|
||||
}
|
||||
function init(){
|
||||
$player = $('<div>').addClass('player')
|
||||
$progress = $('<span>').addClass('progress')
|
||||
$state = $('<span>').addClass('state').on('click',toggle)
|
||||
$title = $('<span>').addClass('title')
|
||||
$lyric = $('<span>').addClass('lyric').hide()
|
||||
$list = $('<ol>').addClass('list')
|
||||
$player.append($progress, $state, $title, $lyric)
|
||||
$('body').append($player)
|
||||
}
|
||||
function play(){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('play')
|
||||
$state.addClass('playing')
|
||||
if($jplayer.jPlayer.hasLyric){
|
||||
$title.hide()
|
||||
$lyric.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
function pause(){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('pause')
|
||||
$state.removeClass('playing')
|
||||
if($jplayer.jPlayer.hasLyric){
|
||||
$title.show()
|
||||
$lyric.hide()
|
||||
$player.attr('title',$title.text())
|
||||
}
|
||||
}
|
||||
}
|
||||
function toggle(){
|
||||
$state.hasClass('playing') ? pause() : play()
|
||||
}
|
||||
})(window, document, jQuery)
|
||||
|
||||
BIN
MyPlayer/assets/swf/Jplayer.swf
Normal file
BIN
MyPlayer/assets/swf/Jplayer.swf
Normal file
Binary file not shown.
Reference in New Issue
Block a user