Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望可以添加音乐播放器功能 #165

Open
moecasts opened this issue Nov 1, 2019 · 8 comments
Open

希望可以添加音乐播放器功能 #165

moecasts opened this issue Nov 1, 2019 · 8 comments

Comments

@moecasts
Copy link

moecasts commented Nov 1, 2019

参考插件 https://github.com/MoePlayer/hexo-tag-aplayer

@ikeq
Copy link
Owner

ikeq commented Nov 2, 2019

现在用这个插件没效果吗

@moecasts
Copy link
Author

moecasts commented Nov 4, 2019

@ikeq 是的,由于是异步渲染的缘故,那个插件中 meting 功能监听的 DOMContentLoaded不会触发。

@ikeq
Copy link
Owner

ikeq commented Nov 12, 2019

hexo/_config.yml

aplayer:
  asset_inject: false

themes/inside/_config.yml

plugins:
  - https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.css
  - https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js

亲测可行,只有一个问题,尚没有很好的机制销毁播放器(路由改变后)。

@ikeq
Copy link
Owner

ikeq commented Nov 12, 2019

我后期实现一些自定义事件类型(包括但不限于 Angular 路由变化),之后就可以很方便做一些善后动作了,例如:

document.addEventListener('route:after', function({ type }) {
  // type: post | page | etc...
});

@moecasts
Copy link
Author

@ikeq 请问您试了 meting 功能吗?原生功能是可以的,但是我试的 meting 功能貌似不行。

@ikeq
Copy link
Owner

ikeq commented Nov 13, 2019

这个插件提供的 meting 功能是基于 MetingJS@1.x,不好处理,但这个 MetingJS 已经到 2.x 了,基于 web components,很完美,所以只需要:

  1. 使用 MetingJS@2.x
  2. patch 一下 hexo-tag-aplayer 的输出结果使之生成 MetingJS@2.x 的标记,具体为:
// themes/inside/scripts/patch.js (名字随意)
const meting = hexo.extend.tag.env.getExtension('meting')

if (meting) {
  hexo.extend.tag.env.removeExtension('meting')
  hexo.extend.tag.register('meting', function (args) {
    /** @type {string} */
    const html = meting.fn.call(hexo, args);

    if (html.trim().startsWith('<div')) {
      return '<meting-js ' + html.match(/[\w-]+\="[\w-]+"/g)
        .filter(i => i.startsWith('data-'))
        .map(i => i.substring(5))
        .join(' ') + '></meting-js>';
    }

    return html
  });
}

其他配置也是需要的:

# hexo/_config.yml
aplayer:
  asset_inject: false
  meting: true
# themes/inside/_config.yml
plugins:
  - https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.css
  - https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js
  - https://unpkg.com/meting@2.0.1/dist/Meting.min.js

Have fun!

@moecasts
Copy link
Author

@ ikeq 测试成功了,感谢您的帮助 :)

如果可以内置该功能的话就更好了,音乐播放器功能还是很常用的。

@pinkpeachabc
Copy link

pinkpeachabc commented Aug 27, 2020

这个测试成功了,但是如果想要全局实现aplayer的吸底模式,却只能点击展开和图片上的播放键,展开后右侧的按钮失灵。像是被右侧的博客挡住了一样 不能点击 其他都是正常的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants