Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jrotty authored Apr 11, 2022
1 parent b9834fa commit 2d51fb7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 67 deletions.
106 changes: 53 additions & 53 deletions YoduBGM/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package YoduBGM
* @author Jrotty
* @version 1.6.0
* @link http://qqdie.com/archives/typecho-yodubgm.html
* @version 1.7.0
* @link http://blog.zezeshe.com
*/
class YoduBGM_Plugin implements Typecho_Plugin_Interface
{
Expand All @@ -17,36 +17,45 @@ public static function activate()
/* 禁用插件方法 */
public static function deactivate(){}
public static function config(Typecho_Widget_Helper_Form $form){
$bof = new Typecho_Widget_Helper_Form_Element_Radio(
'bof', array('0'=> '不自动播放', '1'=> '自动播放'), 0, '播放设置',
'自动播放顾名思义,就是页面打开后音乐就会自动播放');
$form->addInput($bof);
$d=array('默认配置');
$n=5;
while ($n<=200) {
$d[$n] = $n.'px';$n=$n+5;
}

$set1 = new Typecho_Widget_Helper_Form_Element_Select('top', $d, NULL, _t('距离顶部间距'), _t('播放器按钮显示在网页的右上角,这里的设置就是播放器组件距离顶部的间距,默认为65px'));
$form->addInput($set1);

$sxj = new Typecho_Widget_Helper_Form_Element_Radio(
$set2 = new Typecho_Widget_Helper_Form_Element_Radio(
'sxj', array('0'=> '隐藏', '1'=> '不隐藏'), 0, '手机端是/否隐藏',
'');
$form->addInput($sxj);
$musicList = new Typecho_Widget_Helper_Form_Element_Textarea('musicList', NULL,
$form->addInput($set2);
$set3 = new Typecho_Widget_Helper_Form_Element_Textarea('musicList', NULL,
'',_t('歌曲列表'), _t('
<div style="
background: #fff;
<div style="background: #3f51b5;
color: #fff;
padding: 10px;
margin-top: -0.5em;
">填写格式<p><b>直链方式:</b><br>填写歌曲链接地址即可,多首歌曲的话请在两首歌曲之间加换行,千万别多加回车换行。</p>
<p><b>调用网易云:</b><br>书写网易云歌曲id即可,多首歌曲的话请在两首歌曲id之间加换行,单首歌曲直接写id就行,千万别多加回车换行</p>
<p><b>注意:</b><br>这两种填写方式不能混合输入,要么只用直链方式,要么只用网易云方式</p>
<p><b>感谢:</b>https://api.imjad.cn/cloudmusic.md</p>
</div>
'));
$form->addInput($musicList);
$form->addInput($set3);

// 开场音乐
$set4 = new Typecho_Widget_Helper_Form_Element_Text('kaichang', NULL, NULL, _t('开场音乐'), _t('最开始播放的音乐,因为歌曲列表默认为随机播放,但是如果我们想在开场加个音效旁白,就可以将音乐放在这里,这里支持直链或网易云id,只能填一个音频'));
$form->addInput($set4);
}

public static function personalConfig(Typecho_Widget_Helper_Form $form){}
public static function header(){
$cssUrl = Helper::options()->pluginUrl . '/YoduBGM/css/player.css';
$cssUrl = Helper::options()->pluginUrl . '/YoduBGM/css/player.css?2022';
echo '<link rel="stylesheet" href="' . $cssUrl . '">';
if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduBGM')->sxj=='0'){
echo '<style>@media only screen and (max-width:766px){.ymusic{display:none}}</style>'. "\n";
}
if(Helper::options()->Plugin('YoduBGM')->top){
echo '<style>bgm{top: '.Helper::options()->Plugin('YoduBGM')->top.'px;}</style>'. "\n";
}
}

Expand All @@ -55,54 +64,45 @@ public static function footer(){
if(empty($musicList)){
$musicList = "761323";
}

if(strpos($musicList,'//')===false){
$musicList = str_replace(PHP_EOL, '&br=128000&raw=ture"},{mp3:"//api.imjad.cn/cloudmusic/?type=song&id=', $musicList);
$musicList = '{mp3:"//api.imjad.cn/cloudmusic/?type=song&id='.$musicList.'&br=128000&raw=ture"}';
$musicList = str_replace(array("\r\n", "\r", "\n", " "), "", $musicList);
}else{
$musicList = str_replace(PHP_EOL, '"},{mp3:"', $musicList);
$musicList = '{mp3:"'.$musicList.'"}';
$musicList = str_replace(array("\r\n", "\r", "\n", " "), "", $musicList);

}
if(strpos($musicList,',')===false){

echo '
<bgm>
<a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a>
</bgm>
';
}else{

echo '
<bgm>
<a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a><a class="ymusic" onclick="next();" id="ydnext" target="_blank"><i class="iconfont icon-you"></i></a>
</bgm>
';

}
$array = explode(PHP_EOL,$musicList);$playList='';$p=1;
shuffle($array);
if($options->kaichang){$p=2;
array_unshift($array,$options->kaichang);
}
foreach ($array as $value) {
$value = trim($value);
if (substr($value,0,4) === 'http') {
$playList .= '{mp3:"'.$value.'"},';
}
if (is_numeric($value)) {
$playList .= '{mp3:"https://music.163.com/song/media/outer/url?id='.$value.'.mp3"},';
}
//if (preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]+$/',$value)) {
// $playList .= '{mp3:"https://www.xxxxxx.com/tool/music/qq.php?id='.$value.'"},';
//}
}

if (count($array) <= $p) {
echo '<bgm><a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a></bgm>';
} else {
echo '<bgm><a class="ymusic" onclick="playbtu();" target="_blank"><i id="ydmc"></i></a><a class="ymusic" onclick="next();" id="ydnext" target="_blank"><i class="iconfont icon-you"></i></a></bgm>';
}





echo '<script data-no-instant>
var yaudio = new Audio();
yaudio.controls = true;
var musicArr=[
'.$musicList.'
];
/*首次随机播放*/
var a=parseInt(Math.random()*musicArr.length);
var musicArr=['.$playList.'];
var a=0;
var sj=musicArr[a];
yaudio.src=sj.mp3;
';
if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduBGM')->bof=='1'){
echo 'yaudio.play();</script>'. "\n";
}else{ echo '</script>'. "\n";
}
echo '<script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/player.js" data-no-instant></script><script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/prbug.js"></script>' . "\n";
yaudio.volume = 0.68;
</script>'. "\n";
echo '<script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/player.js?2022" data-no-instant></script><script src="'.Helper::options()->pluginUrl . '/YoduBGM/js/prbug.js"></script>' . "\n";
}

}
20 changes: 10 additions & 10 deletions YoduBGM/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
这个是typecho博客插件
这个是Typecho博客插件

## 插件特色

1,这是一款简洁BGM播放器,需要您的主题支持pjax或者instantclick才能保证页面切换依旧播放

2,支持多首歌曲,且默认随机播放

3,可设置是否自动播放(部分手机浏览器不支持
3,支持网易云音乐调用(不保证api永远有效

4,支持网易云音乐调用(不保证api永远有效)
4,当你按照格式只填写一首歌曲时,插件会默认隐藏掉切歌按钮,只保留播放按钮,使其更加简洁

5,当你按照格式只填写一首歌曲时,插件会默认隐藏掉切歌按钮,只保留播放按钮,使其更加简洁
5,插件使用了原生js,所以无需加载jq等js框架

6,插件使用了原生js,所以无需加载jq等js框架

7,整个插件所需要加载的文件不到5kb,可谓是非常小巧了
6,整个插件所需要加载的文件不到5kb,可谓是非常小巧了

## 使用方法

Expand All @@ -28,11 +26,13 @@

直接填写单个歌曲id即可,多个id的话,之间用回车隔开

## 感谢

api提供:
## 1.7.0升级内容
增加播放错误跳到下一曲,默认歌曲音量为当前音量的68%,直链与网易云id支持混填,感谢@daxiyun
新增开场音乐设置

https://api.imjad.cn/cloudmusic.md
## 1.6.5升级内容
时隔4年的重新维护,删除失效的api改用网易云自己的api,新增一项间距设置,重写css样式。

## 1.6.0升级内容

Expand Down
29 changes: 25 additions & 4 deletions YoduBGM/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@
font-style: normal
}

bgm [class*=" icon-"],bgm [class^=icon-]{font-family:ydbgm!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
bgm [class*=" icon-"],bgm [class^=icon-]{font-family:ydbgm!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-size: 16px;}

.icon-music:before{content:"\f001"}.icon-you:before{content:"\f105"}.icon-bofang:before{content:"\f1d8"}



.ymusic{z-index:999;position:fixed;right:5px;top:57px;width:24px;height:24px;line-height:24px;text-align:center;border-radius:5px;background:#fff;color:red;cursor:pointer;box-shadow:0 0 8px #555}bgm a,bgm a:hover{text-decoration:none}bgm a:hover{color:#2479CC}#ydnext{top: 96px;}@media only screen and (min-width:767px){.ymusic {top: 5px;}#ydnext{top: 44px;}}
bgm {
position: fixed;
right: 5px;
top: 65px;
}
bgm a {
display: flex;
background: white;
margin-bottom: 10px;
width: 30px;
height: 30px;
border-radius: 100%;
align-items: center;
justify-content: center;
padding: 8px;
color: red;
cursor: pointer;
-moz-box-shadow:3px 3px 6px #858585; -webkit-box-shadow:3px 3px 6px #858585; box-shadow:3px 3px 6px #858585;
}
.dark bgm a{
background: #1f2937;
-moz-box-shadow:3px 3px 6px #718096; -webkit-box-shadow:3px 3px 6px #718096; box-shadow:3px 3px 6px #718096;
color: white;
}
4 changes: 4 additions & 0 deletions YoduBGM/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ function() {
next();
},
false);

yaudio.addEventListener("error", function() {
next();
}, false);

0 comments on commit 2d51fb7

Please sign in to comment.