KodExplorer/plugins/jPlayer/static/main.js

139 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-08-23 19:40:27 +00:00
kodReady.push(function(){
var playerSupport = function(){
var support = {
wap:{//移动端
music:['mp3','m4a','aac'],
movie:['mp4','m4v','mov']
2018-07-05 13:50:52 +00:00
},
2017-08-23 19:40:27 +00:00
ie:{
music:['mp3','m4a','aac'],
movie:['mp4','m4v','mov' , 'flv','f4v']
},
chrome:{//default chrome,firefox,edge
2018-07-05 13:50:52 +00:00
music:['mp3','wav','aac', 'm4a','oga','ogg','webma','flac'],
2017-08-23 19:40:27 +00:00
movie:['mp4','m4v','mov', 'f4v','flv','ogv','webm','webmv']
}
//safari 已经禁用了flash
};
var res = support.chrome;
if(isWap()){
res = support.wap;
}else if(!!window.ActiveXObject || "ActiveXObject" in window){
res = support.ie;
}
return res.music.join(',') + ',' + res.movie.join(',');
}
//'mp3,wav,m4a,aac,oga,ogg,webma,mp4,m4v,flv,mov,f4v,ogv,webm,webmv'
2018-07-05 13:50:52 +00:00
var myPlayer;
var loadMyPlayer = function(callback){
var appStatic = "{{pluginHost}}static/";
var appStaticDefault = "{{pluginHostDefault}}static/";
if(myPlayer){
callback(myPlayer);
}else{
var top = ShareData.frameTop();
top.require.async(appStatic+'page.js',function(app){
if(!myPlayer){
myPlayer = app;
myPlayer.init(appStatic,appStaticDefault);
}
callback(myPlayer);
});
}
};
2017-08-23 19:40:27 +00:00
kodApp.add({
name:"jPlayer",
title:LNG['Plugin.default.jPlayer'],
ext:playerSupport(),
//ext:"{{config.fileExt}}",
sort:"{{config.fileSort}}",
2018-07-05 13:50:52 +00:00
icon:'{{pluginHost}}static/images/icon.png',
2017-08-23 19:40:27 +00:00
callback:function(path,ext){
2018-07-05 13:50:52 +00:00
var music = ['mp3','wav','aac','m4a','oga','ogg','webma','m3u8a','m3ua','flac'];
2018-08-22 14:55:14 +00:00
if(isWap() && $.inArray(ext, music) == -1 && G.ACT != 'file' ){ //移动端,非视频文件分享页面用跳转方式打开
2018-07-05 13:50:52 +00:00
return window.open(core.path2url(path));
2017-12-01 12:24:53 +00:00
}
2017-08-23 19:40:27 +00:00
var list = [{
url:core.path2url(path),
name:urlDecode(core.pathThis(path)),//zip内文件播放
ext:ext
}];
2018-07-05 13:50:52 +00:00
if(isWap() && !window.jplayerInit){
window.jplayerInit = true;
$(".jPlayer-music .play-list .remove").trigger("click");
$.addStyle('.music-player-dialog{visibility:visible;}');
}
2017-08-23 19:40:27 +00:00
loadMyPlayer(function(player){
player.play(list);
});
}
});
2018-07-05 13:50:52 +00:00
// 移动端安卓首次打开播放器不自动播放问题处理;
if(isWap()){
$.addStyle('.music-player-dialog{visibility:hidden;}');
2018-08-22 14:55:14 +00:00
// loadMyPlayer(function(player){
// player.play([{url:"",name:"",ext:"mp3"}]);
// });
2018-07-05 13:50:52 +00:00
}
2017-08-23 19:40:27 +00:00
//音效播放绑定
Hook.bind('playSound',function(url){
loadMyPlayer(function(player){
player.playSound(url);
});
});
2018-07-05 13:50:52 +00:00
2017-08-23 19:40:27 +00:00
//多选含有音乐右键菜单
var menuOpt = {
'play-media':{
name:LNG.add_to_play,
className:"play-media hidden",
icon:"x-item-file x-mp3",
accesskey: "p",
callback:function(action,option){
if (ui.fileLight.fileListSelect().length <1) return;
var list = [];//选中单个&多个都可以播放
ui.fileLight.fileListSelect().each(function(index){
2018-07-05 13:50:52 +00:00
var ext = ui.fileLight.type($(this));
if ( kodApp.appSupportCheck('jPlayer',ext) ) {
2017-08-23 19:40:27 +00:00
var path = ui.fileLight.path($(this));
var url = core.path2url(path,false);
list.push({
url:url,
name:core.pathThis(path),
2018-07-05 13:50:52 +00:00
ext:ext
2017-08-23 19:40:27 +00:00
});
}
});
loadMyPlayer(function(player){
player.play(list);
});
}
}
}
$.contextMenu.menuAdd(menuOpt,'.menu-more',false,'.clone');
//多选含有音乐检测;添加到音乐列表
Hook.bind('rightMenu.show.menu-more',function($menuAt,$theMenu){
var needMenu = 0;
var hideClass = 'hidden';
ui.fileLight.fileListSelect().each(function(){
var ext = core.pathExt(ui.fileLight.name($(this)));
if ( kodApp.appSupportCheck('jPlayer',ext) ){
needMenu +=1;
}
});
if(needMenu == 0){
$theMenu.find('.play-media').addClass(hideClass);
}else{
$theMenu.find('.play-media').removeClass(hideClass);
}
});
});