qzmjef 发表于 2024-11-7 08:11:31

Hexo添加音乐播放器


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、</span>前言</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">为博客添加音乐播放器功能,网上有<span style="color: black;">非常多</span>种方式,<span style="color: black;">亦</span>有<span style="color: black;">非常多</span>插件<span style="color: black;">能够</span>用,<span style="color: black;">例如</span><span style="color: black;">aplayer</span>、<span style="color: black;">dplayer</span>等等。<span style="color: black;">安排</span>方式既<span style="color: black;">能够</span><span style="color: black;">运用</span><span style="color: black;">hexo插件</span>,<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">经过</span>提取<span style="color: black;">dist文件</span>的方式。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">自己</span>为自己的播放<span style="color: black;">选取</span>的<span style="color: black;">aplayer</span>播放器,一<span style="color: black;">起始</span>是<span style="color: black;">运用</span><span style="color: black;">hexo插件</span>的方式,<span style="color: black;">然则</span><span style="color: black;">安排</span>的时候<span style="color: black;">始终</span>报标签解析的错误,查了好久<span style="color: black;">亦</span>没查到<span style="color: black;">原由</span>,无奈,放弃<span style="color: black;">运用</span>插件的方式,改为<span style="color: black;">运用</span>提取<span style="color: black;">aplayer</span>的<span style="color: black;">dist文件</span>的方式。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、</span>下载aplayer</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">拜访</span><span style="color: black;">aplayer</span>源码:[<span style="color: black;">GitHub Aplayer</span>](<span style="color: black;"><span style="color: black;">https://github.com/MoePlayer/APlayer</span></span>) ,将文件下载到本地,解压后将dist文件夹复制到 <span style="color: black;">/themes/next/source</span> 文件夹下。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3、</span>创建样式</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.1、新建<span style="color: black;">music.js</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">/themes/next/source/dist</span>文件夹中新建<span style="color: black;">music.js</span>文件,将下面代码添加进去:</p><span style="color: black;">const</span> <span style="color: black;">ap</span> <span style="color: black;">=</span> <span style="color: black;">new</span> <span style="color: black;">APlayer({</span>
    <span style="color: black;">container:</span> <span style="color: black;">document.getElementById(aplayer),</span>
    <span style="color: black;">autoplay:</span> <span style="color: black;">false</span><span style="color: black;">,</span>
    <span style="color: black;">loop:</span> <span style="color: black;">all</span><span style="color: black;">,</span>
    <span style="color: black;">volume:</span> <span style="color: black;">0.7</span><span style="color: black;">,</span>
    <span style="color: black;">listFolded:</span> <span style="color: black;">true</span><span style="color: black;">,</span>
    <span style="color: black;">listMaxHeight:</span> <span style="color: black;">60</span><span style="color: black;">,</span>
    <span style="color: black;">audio:</span> <span style="color: black;">[</span>
    <span style="color: black;">{</span>
    <span style="color: black;">name:</span> <span style="color: black;">name1</span><span style="color: black;">,</span>
    <span style="color: black;">artist:</span> <span style="color: black;">artist1</span><span style="color: black;">,</span>
    <span style="color: black;">url:</span> <span style="color: black;">url1.mp3</span><span style="color: black;">,</span>
    <span style="color: black;">cover:</span> <span style="color: black;">cover1.jpg</span><span style="color: black;">,</span>
    <span style="color: black;">},</span>
    <span style="color: black;">{</span>
    <span style="color: black;">name:</span> <span style="color: black;">name2</span><span style="color: black;">,</span>
    <span style="color: black;">artist:</span> <span style="color: black;">artist2</span><span style="color: black;">,</span>
    <span style="color: black;">url:</span> <span style="color: black;">url2.mp3</span><span style="color: black;">,</span>
    <span style="color: black;">cover:</span> <span style="color: black;">cover2.jpg</span><span style="color: black;">,</span>
    <span style="color: black;">}</span>
    <span style="color: black;">]</span>
    <span style="color: black;">});</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.2、参数修改</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面代码为你在<span style="color: black;">hexo</span>上生成<span style="color: black;">aplayer</span>播放器的样式,参数修改参考 [<span style="color: black;">官方中文文档</span>](<span style="color: black;">https://aplayer.js.org/#/zh-Hans/?id=%E5%8F%82%E6%95%B0</span>) 。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3、修改aplayer样式</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3.1、普通模式:</p><span style="color: black;">const</span> ap = <span style="color: black;">new</span> APlayer({
    <span style="color: black;">container</span>: <span style="color: black;">document</span>.getElementById(<span style="color: black;">aplayer</span>),
    <span style="color: black;">audio</span>: [{
    <span style="color: black;">name</span>: <span style="color: black;">name</span>,
    <span style="color: black;">artist</span>: <span style="color: black;">artist</span>,
    <span style="color: black;">url</span>: <span style="color: black;">url.mp3</span>,
    <span style="color: black;">cover</span>: <span style="color: black;">cover.jpg</span>
    }]
    });<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/86fceeb4695c484ab05d1af0091f488d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=JuKS1%2FspeWBgXoV2YEq1f9DA2%2Bk%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3.2、播放列表模式:</p><span style="color: black;">const</span> <span style="color: black;">ap</span> <span style="color: black;">=</span> <span style="color: black;">new</span> <span style="color: black;">APlayer({</span>
    <span style="color: black;">container:</span> <span style="color: black;">document.getElementById(player),</span>
    <span style="color: black;">listFolded:</span> <span style="color: black;">false</span><span style="color: black;">,//列表默认折叠</span>
    <span style="color: black;">listMaxHeight:</span> <span style="color: black;">90</span><span style="color: black;">,//列表最大高度</span>
    <span style="color: black;">lrcType:</span> <span style="color: black;">3</span><span style="color: black;">,</span> <span style="color: black;">//此为歌词格式,<span style="color: black;">无</span>歌词<span style="color: black;">能够</span>直接删掉这一行</span>
    <span style="color: black;">audio:</span> <span style="color: black;">[</span>
    <span style="color: black;">{</span>
    <span style="color: black;">name:</span> <span style="color: black;">name1</span><span style="color: black;">,</span>
    <span style="color: black;">artist:</span> <span style="color: black;">artist1</span><span style="color: black;">,</span>
    <span style="color: black;">url:</span> <span style="color: black;">url1.mp3</span><span style="color: black;">,</span>
    <span style="color: black;">cover:</span> <span style="color: black;">cover1.jpg</span><span style="color: black;">,</span>
    <span style="color: black;">lrc:</span> <span style="color: black;">lrc1.lrc</span><span style="color: black;">,</span>
    <span style="color: black;">theme:</span> <span style="color: black;">#ebd0c2</span>
    <span style="color: black;">},</span>
    <span style="color: black;">{</span>
    <span style="color: black;">name:</span> <span style="color: black;">name2</span><span style="color: black;">,</span>
    <span style="color: black;">artist:</span> <span style="color: black;">artist2</span><span style="color: black;">,</span>
    <span style="color: black;">url:</span> <span style="color: black;">url2.mp3</span><span style="color: black;">,</span>
    <span style="color: black;">cover:</span> <span style="color: black;">cover2.jpg</span><span style="color: black;">,</span>
    <span style="color: black;">lrc:</span> <span style="color: black;">lrc2.lrc</span><span style="color: black;">,</span>
    <span style="color: black;">theme:</span> <span style="color: black;">#46718b</span>
    <span style="color: black;">}</span>
    <span style="color: black;">]</span>
    <span style="color: black;">});</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/71c7997daba74e22b26a17068f73d6fb~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=ETzbMJlefVRJMFKILaR9Xwv%2FK1o%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3.3、吸底模式:</p><span style="color: black;">const</span> ap = <span style="color: black;">new</span> APlayer({
    container: document.getElementById(<span style="color: black;">player</span>),
    <span style="color: black;">fixed</span>: <span style="color: black;">true</span>,
    audio: [{
    name: <span style="color: black;">name</span>,
    artist: <span style="color: black;">artist</span>,
    url: <span style="color: black;">url.mp3</span>,
    cover: <span style="color: black;">cover.jpg</span>,
    }]
    });<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/26ca7abdfdef4170b7df40cd000ed391~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=VhcFCYmFqwIT2Tker6JCCeEgf8I%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3.4、迷你底模式:</p><span style="color: black;">const</span> ap = <span style="color: black;">new</span> APlayer({
    <span style="color: black;">container</span>: <span style="color: black;">document</span>.getElementById(<span style="color: black;">player</span>),
    <span style="color: black;">mini</span>: <span style="color: black;">true</span>,
    <span style="color: black;">audio</span>: [{
    <span style="color: black;">name</span>: <span style="color: black;">name</span>,
    <span style="color: black;">artist</span>: <span style="color: black;">artist</span>,
    <span style="color: black;">url</span>: <span style="color: black;">url.mp3</span>,
    <span style="color: black;">cover</span>: <span style="color: black;">cover.jpg</span>,
    }]
    });<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.4、附上我的参数:</p><span style="color: black;">const</span> ap = <span style="color: black;">new</span>APlayer({<span style="color: black;">container</span>: <span style="color: black;">document</span>.getElementById(<span style="color: black;">aplayer</span>), <span style="color: black;">//播放器容器元素</span>
    <span style="color: black;">listFolded</span>: <span style="color: black;">false</span>, <span style="color: black;">//列表默认折叠</span>
    <span style="color: black;">listMaxHeight</span>: <span style="color: black;">90</span>, <span style="color: black;">//列表最大高度</span>
    <span style="color: black;">//lrcType: 3, //此为歌词格式,<span style="color: black;">无</span>歌词<span style="color: black;">能够</span>直接删掉这一行</span>
    <span style="color: black;">mini</span>:<span style="color: black;">false</span>, <span style="color: black;">//迷你模式</span>
    <span style="color: black;">autoplay</span>: <span style="color: black;">true</span>, <span style="color: black;">//自动播放</span>
    <span style="color: black;">theme</span>: <span style="color: black;">#FADFA3</span>, <span style="color: black;">//主题色</span>
    <span style="color: black;">loop</span>: <span style="color: black;">all</span>, <span style="color: black;">//音频循环播放, 可选值: all<span style="color: black;">所有</span>循环, one单曲循环, none不循环</span>
    <span style="color: black;">order</span>: <span style="color: black;">list</span>, <span style="color: black;">//音频循环<span style="color: black;">次序</span>, 可选值: list列表循环, random随机循环</span>
    <span style="color: black;">preload</span>: <span style="color: black;">auto</span>, <span style="color: black;">//预加载,可选值: none, metadata, auto</span>
    <span style="color: black;">volume</span>: <span style="color: black;">0.7</span>, <span style="color: black;">//默认音量,请<span style="color: black;">重视</span>播放器会记忆用户设置,用户手动设置音量后默认音量即失效</span>
    <span style="color: black;">mutex</span>: <span style="color: black;">false</span>, <span style="color: black;">//互斥,阻止多个播放器<span style="color: black;">同期</span>播放,当前播放器播放时暂停其他播放器</span>
    <span style="color: black;">audio</span>: [ <span style="color: black;">//音频信息</span>
    {
    <span style="color: black;">name</span>: <span style="color: black;">大鱼</span>, <span style="color: black;">//音频名<span style="color: black;">叫作</span></span>
    <span style="color: black;">artist</span>: <span style="color: black;">周深、郭沁</span>, <span style="color: black;">//音频艺术家</span>
    <span style="color: black;">url</span>: <span style="color: black;">"http://lc-tguve1gk.cn-n1.lcfile.com/47b5548df9c80bba84f4/%E5%91%A8%E6%B7%B1%E3%80%81%E9%83%AD%E6%B2%81%20-%20%E5%A4%A7%E9%B1%BC%20%282017%E4%B8%AD%E5%9B%BD%E6%96%B0%E6%AD%8C%E5%A3%B0%E7%AC%AC%E4%BA%8C%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F%E7%8E%B0%E5%9C%BA%E4%BC%B4%E5%A5%8F%29.mp3</span>, <span style="color: black;">//音频链接</span>
    <span style="color: black;">cover</span>: <span style="color: black;">http://lc-tguve1gk.cn-n1.lcfile.com/a9fff99abbddc8757d4b/%E5%A4%A7%E9%B1%BC.jpg</span>, <span style="color: black;">//音频封面</span>
    <span style="color: black;">//lrc: lrc1.lrc, //歌词</span>
    <span style="color: black;">theme</span>: <span style="color: black;">#ebd0c2</span> <span style="color: black;">//切换到此音频时的主题色,比上面的 theme 优先级高</span>
    },
    {
    <span style="color: black;">name</span>: <span style="color: black;">Something just like this</span>,
    <span style="color: black;">artist</span>: <span style="color: black;">Alex Goot _ Madilyn Bailey</span>,
    <span style="color: black;">url</span>: <span style="color: black;">http://lc-tguve1gk.cn-n1.lcfile.com/f3bee3260fa207648d34/Alex%20Goot%20_%20Madilyn%20Bailey%20-%20Something%20Just%20Like%20This.mp3</span>,
    <span style="color: black;">cover</span>: <span style="color: black;">http://lc-tguve1gk.cn-n1.lcfile.com/d21b8e3392433807b1e2/Something%20just%20like%20this.jpg</span>,
    <span style="color: black;">//lrc: lrc2.lrc,</span>
    <span style="color: black;">theme</span>: <span style="color: black;">#46718b</span>
    }
    ]
    });<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4、</span><span style="color: black;">安排</span> </p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">aplayer</span>的样式设置好之后就<span style="color: black;">能够</span>把aplayer放在自己想要<span style="color: black;">安置</span>的位置上,<span style="color: black;">安置</span>代码如下:</p><span style="color: black;">&lt;<span style="color: black;">link</span> <span style="color: black;">rel</span>=<span style="color: black;">"stylesheet"</span> <span style="color: black;">href</span>=<span style="color: black;">"/dist/APlayer.min.css"</span>&gt;</span>
    <span style="color: black;">&lt;<span style="color: black;">div</span> <span style="color: black;">id</span>=<span style="color: black;">"aplayer"</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">div</span>&gt;</span>
    <span style="color: black;">&lt;<span style="color: black;">script</span> <span style="color: black;">type</span>=<span style="color: black;">"text/javascript"</span> <span style="color: black;">src</span>=<span style="color: black;">"/dist/APlayer.min.js"</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">script</span>&gt;</span>
    <span style="color: black;">&lt;<span style="color: black;">script</span> <span style="color: black;">type</span>=<span style="color: black;">"text/javascript"</span> <span style="color: black;">src</span>=<span style="color: black;">"/dist/music.js"</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">script</span>&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将<span style="color: black;">安置</span>代码放在<span style="color: black;">区别</span>的<span style="color: black;"><span style="color: black;">/themes/next/layout/xxx.swig</span></span>文件内会有<span style="color: black;">区别</span>的效果。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">每一个</span>人<span style="color: black;">运用</span>的主题不<span style="color: black;">同样</span>,要<span style="color: black;">按照</span>自己的主题去调试。例如我用的是<span style="color: black;">next-mist</span>主题,且<span style="color: black;">爱好</span><span style="color: black;">安置</span>在侧边栏。<span style="color: black;">那样</span>在<span style="color: black;"><span style="color: black;">/themes/next/layout/_marco</span></span>文件夹下找到<span style="color: black;">sidebar.swig</span>文件。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>要<span style="color: black;">安置</span>在侧边栏的<span style="color: black;">友链</span>下面,<span style="color: black;">那样</span>在<span style="color: black;">sidebar.swig</span>中找到<span style="color: black;">if theme.links</span>,将<span style="color: black;">安置</span>代码添加到<span style="color: black;">endif</span>之后。如下图:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/798ec16a61a84a08bae7695993a388a6~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=bdwNCPHykSNGEEaRo3F0hyWbDPg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">如要<span style="color: black;">安置</span>到<span style="color: black;">RSS</span>下就在<span style="color: black;">sidebar.swig</span>中搜索<span style="color: black;">if theme.rss</span>,<span style="color: black;">亦</span>是添加到<span style="color: black;">endif</span>之后。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">我是<span style="color: black;">选取</span>放在了友链下方,如下图:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/fb3d730949014ff8adc23abc67f0a72b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=FKlGa7i%2BjC0ZBXjRjDCBZFWakHo%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">最后</span>效果如下图:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/3995bef80d3a4cda8bf77fa5936e0a5a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=lHMoeoiE1VVSjl3bIPwZVgx5aW0%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">5、</span>制作音乐/<span style="color: black;">照片</span>外链</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">正如之前为博客添加评论及统计功能的时候,<span style="color: black;">咱们</span><span style="color: black;">运用</span>了<span style="color: black;">LeanCloud</span>,制作音乐/<span style="color: black;">照片</span>的外链<span style="color: black;">一样</span><span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">运用</span>它。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">注册、登陆的<span style="color: black;">过程</span>在之前的<span style="color: black;">文案</span>里<span style="color: black;">已然</span>描绘过了,<span style="color: black;">这儿</span><span style="color: black;">再也不</span>详述,<span style="color: black;">咱们</span>直接步入正题。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">到你创建的应用里面去,点击存储,如下图。点击<span style="color: black;">_File</span>,点击上传,找到你下载好的音乐文件和音乐<span style="color: black;">照片</span>上传上去就行了。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/37280cdca30f4b5ea0009fbf21b48152~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=aSODY%2FBDyxRDbuYfDQT54MI2Jqs%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上传之后刷新页面,将列表向后拉,就<span style="color: black;">能够</span>看到对应的音乐和<span style="color: black;">照片</span>的url连接了。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/1b277eb248104a51aa87c49c0629b8bd~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1730020854&amp;x-signature=E1%2FF2dbPDg79wtZUHmmbrAAH8iw%3D" style="width: 50%; margin-bottom: 20px;"></div>




页: [1]
查看完整版本: Hexo添加音乐播放器