Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19dab80cb2 | ||
|
|
e50b13d8f6 | ||
|
|
375c0f7ea1 | ||
|
|
70f2e00e13 | ||
|
|
d54700af5f | ||
|
|
8f8cc489a2 | ||
|
|
420c5db9f4 | ||
|
|
fc1a04b303 | ||
|
|
bada61d667 | ||
|
|
93e28a37ee | ||
|
|
ddc529397d | ||
|
|
714d57b248 | ||
|
|
591b6b5cff | ||
|
|
5e610b15e8 | ||
|
|
2ce5681b7e | ||
|
|
41478dc5f9 | ||
|
|
ec0c5c3c05 | ||
|
|
21ca7d7b9a | ||
|
|
f4ffe98bf6 | ||
|
|
dedc1bf62d | ||
|
|
a31d911948 | ||
|
|
44ff1c8ff7 | ||
|
|
7b9074ffd0 | ||
|
|
fb4211a0b0 | ||
|
|
cf5972879a | ||
|
|
75b86a6beb | ||
|
|
5cbc875993 | ||
|
|
f29066f1b6 | ||
|
|
021df59e85 | ||
|
|
6029ce980c | ||
|
|
e2e8884a45 | ||
|
|
c590dd4080 | ||
|
|
532dddc3b0 | ||
|
|
b387833730 | ||
|
|
c9e7f8aa11 | ||
|
|
5905d0ed29 | ||
|
|
cd21726da9 | ||
|
|
3c594ebb71 | ||
|
|
e2f2888ea5 | ||
|
|
2287758344 | ||
|
|
a2f96199fe | ||
|
|
2df2cb49a6 | ||
|
|
1ef9d47b80 | ||
|
|
4d1cdb3341 | ||
|
|
29a462487c | ||
|
|
81002c0bf9 | ||
|
|
e3ce22bf7d | ||
|
|
9d772ef052 | ||
|
|
b654f6c6af | ||
|
|
77cc9d9528 | ||
|
|
88aff9111b | ||
|
|
82ca11d126 | ||
|
|
fa59380e4a | ||
|
|
e22933a503 | ||
|
|
1a4ea7a4ed | ||
|
|
80b84affdc | ||
|
|
8a1f19ec57 | ||
|
|
a5c2c58092 | ||
|
|
27c8f6b44c | ||
|
|
e7168ec462 | ||
|
|
17c80e4083 | ||
|
|
fa66dd90f4 | ||
|
|
bd4426ff2b | ||
|
|
c0e868484a | ||
|
|
ea7a97af3f | ||
|
|
a6705d08b1 | ||
|
|
db6e0f8b84 | ||
|
|
00bec0c66e | ||
|
|
275bbfcd07 | ||
|
|
62a9e9f1c7 | ||
|
|
77d00898be | ||
|
|
67e09f7ab6 | ||
|
|
00aac89320 | ||
|
|
1fd103c326 | ||
|
|
6b252a2c5f | ||
|
|
719c5ce3ea | ||
|
|
f6fdb2a49d | ||
|
|
af85763598 | ||
|
|
665b0e7342 | ||
|
|
ceb2bc5feb | ||
|
|
6c019aba08 | ||
|
|
bce02f0016 | ||
|
|
021eb283a3 | ||
|
|
e41fa9901d | ||
|
|
f25e0bf82d | ||
|
|
b88341b233 | ||
|
|
8d690b81df | ||
|
|
1ed95f0045 | ||
|
|
ebd8a48aca | ||
|
|
c8e912788b | ||
|
|
dedcfbf1ac | ||
|
|
f0927af30b | ||
|
|
c6e4085a65 | ||
|
|
8d6f2327b9 | ||
|
|
9a99a327e3 | ||
|
|
9f0a9aecbc | ||
|
|
cbc0f99eee | ||
|
|
c3d98f3aca | ||
|
|
bf566955a8 | ||
|
|
960b8b34fd | ||
|
|
d381582fe4 | ||
|
|
3d64d42305 | ||
|
|
7b4d2320a8 | ||
|
|
6f2174cab4 | ||
|
|
ef1ae2b761 | ||
|
|
6f496ac41c | ||
|
|
287950513d | ||
|
|
584f11ce04 | ||
|
|
53096c4e0b | ||
|
|
c4c3ead825 | ||
|
|
a0467709eb | ||
|
|
230f43f41c | ||
|
|
a2c9072c1f | ||
|
|
9c13dfa7f6 | ||
|
|
4c20d7f8be | ||
|
|
b74b5b0802 | ||
|
|
eec8c3a0ed | ||
|
|
3877378602 | ||
|
|
370d039099 | ||
|
|
634ad2def4 |
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": 0,
|
||||
"no-extra-parens": 1,
|
||||
"block-scoped-var": 1,
|
||||
"curly": 1,
|
||||
"eqeqeq": 1,
|
||||
"no-global-assign": 1,
|
||||
"no-implicit-globals": 1,
|
||||
"no-labels": 1,
|
||||
"no-multi-str": 1,
|
||||
"comma-spacing": 1,
|
||||
"comma-style": 1,
|
||||
"func-call-spacing": 1,
|
||||
"indent": 1,
|
||||
"keyword-spacing": 1,
|
||||
"linebreak-style": 1,
|
||||
"lines-around-comment": 1,
|
||||
"no-multiple-empty-lines": 1,
|
||||
"space-infix-ops": 1,
|
||||
"arrow-spacing": 1,
|
||||
"no-var": 1,
|
||||
"prefer-const": 1,
|
||||
"no-unsafe-negation": 1,
|
||||
"array-callback-return": 1,
|
||||
"dot-location": 1,
|
||||
"dot-notation": 1,
|
||||
"no-eval": 1,
|
||||
"no-extend-native": 1,
|
||||
"no-extra-label": 1,
|
||||
"semi": 1,
|
||||
"space-before-blocks": 1,
|
||||
"space-before-function-paren": 1,
|
||||
"space-in-parens": 1,
|
||||
"space-unary-ops": 1,
|
||||
"spaced-comment": 1,
|
||||
"arrow-body-style": 1,
|
||||
"arrow-parens": 1,
|
||||
"no-restricted-imports": 1,
|
||||
"no-duplicate-imports": 1,
|
||||
"no-useless-computed-key": 1,
|
||||
"no-useless-rename": 1,
|
||||
"rest-spread-spacing": 1,
|
||||
"no-trailing-spaces": 1
|
||||
},
|
||||
"globals": {
|
||||
"require": false,
|
||||
"module": false,
|
||||
"Hls": false,
|
||||
"flvjs": false,
|
||||
"dashjs": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
中文用户请注意:请尽量用**英文**描述你的 issue,这样能够让尽可能多的人帮到你。
|
||||
|
||||
If you want to report a bug, please provide the following information:
|
||||
|
||||
- The steps to reproduce.
|
||||
- A minimal demo of the problem via https://jsfiddle.net or http://codepen.io/pen if possible.
|
||||
- Which versions of APlayer, and which browser / OS are affected by this issue?
|
||||
@@ -1,3 +1,9 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "4.0"
|
||||
- "node"
|
||||
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- node_modules
|
||||
@@ -1,8 +1,6 @@
|
||||
The Star And Thank Author License (SATA)
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 DIYgod(i@html.love)
|
||||
|
||||
Project Url: https://github.com/DIYgod/APlayer
|
||||
Copyright (c) DIYgod <diy.d.god@gmail.com> (https://www.anotherhome.net/)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -14,24 +12,10 @@ furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
And wait, the most important, you shall star/+1/like the project(s) in project url
|
||||
section above first, and then thank the author(s) in Copyright section.
|
||||
|
||||
Here are some suggested ways:
|
||||
|
||||
- Email the authors a thank-you letter, and make friends with him/her/them.
|
||||
- Report bugs or issues.
|
||||
- Tell friends what a wonderful project this is.
|
||||
- And, sure, you can just express thanks in your mind without telling the world.
|
||||
|
||||
Contributors of this project by forking have the option to add his/her name and
|
||||
forked project url at copyright and project url sections, but shall not delete
|
||||
or modify anything else in these two sections.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE.
|
||||
|
||||
@@ -1,224 +1,120 @@
|
||||
# APlayer
|
||||
<p align="center">
|
||||
<img src="https://ws4.sinaimg.cn/large/006tKfTcgy1fhu01y9uy7j305k04s3yc.jpg" alt="ADPlayer" width="100">
|
||||
</p>
|
||||
<h1 align="center">APlayer</h1>
|
||||
|
||||
> Wow, such a lovely HTML5 music player
|
||||
|
||||
[](https://www.npmjs.com/package/aplayer)
|
||||
[](https://cdnjs.com/libraries/aplayer)
|
||||
[](https://github.com/DIYgod/APlayer/blob/master/LICENSE)
|
||||
[](https://david-dm.org/DIYgod/APlayer#info=devDependencies)
|
||||
[](https://github.com/MoePlayer/APlayer/blob/master/LICENSE)
|
||||
[](https://www.npmjs.com/package/aplayer)
|
||||
[](https://travis-ci.org/DIYgod/APlayer)
|
||||
[](https://www.anotherhome.net/)
|
||||
|
||||
> Wow, such a beautiful html5 music player
|
||||
[](https://github.com/MoePlayer/APlayer/tree/master/dist)
|
||||
[](https://travis-ci.org/MoePlayer/APlayer)
|
||||
[](https://david-dm.org/MoePlayer/APlayer#info=devDependencies)
|
||||
[](https://github.com/MoePlayer/APlayer#donate)
|
||||
|
||||
## Introduction
|
||||
|
||||
[Demo](http://aplayer.js.org)
|
||||
|
||||
Using APlayer on your project? [Let me know!](https://github.com/DIYgod/APlayer/issues/79)
|
||||
|
||||
Screenshot
|
||||

|
||||
|
||||
## Install
|
||||
APlayer is a lovely HTML5 music player to help people build audio easily.
|
||||
|
||||
```
|
||||
$ npm install aplayer --save
|
||||
```
|
||||
**APlayer supports:**
|
||||
|
||||
## CDN
|
||||
- Media formats
|
||||
- MP4 H.264 (AAC or MP3)
|
||||
- WAVE PCM
|
||||
- Ogg Theora Vorbis
|
||||
- Features
|
||||
- Playlist
|
||||
- Lyrics
|
||||
|
||||
[cdnjs](https://cdnjs.com/libraries/aplayer)
|
||||
Using APlayer on your project? [Let me know!](https://github.com/MoePlayer/APlayer/issues/79)
|
||||
|
||||
## Usage
|
||||
**[Docs](https://aplayer.js.org)**
|
||||
|
||||
### HTML
|
||||
**[中文文档](https://aplayer.js.org/#/zh-Hans/)**
|
||||
|
||||
```HTML
|
||||
<div id="player1" class="aplayer"></div>
|
||||
<!-- ... -->
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
## Join the Discussion
|
||||
|
||||
### JS
|
||||
|
||||
```JS
|
||||
var ap = new APlayer(option);
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
```JS
|
||||
var option = {
|
||||
element: document.getElementById('player1'), // Optional, player element
|
||||
narrow: false, // Optional, narrow style
|
||||
autoplay: true, // Optional, autoplay song(s), not supported by mobile browsers
|
||||
showlrc: 0, // Optional, show lrc, can be 0, 1, 2, see: ###With lrc
|
||||
mutex: true, // Optional, pause other players when this player playing
|
||||
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
|
||||
mode: 'random', // Optional, play mode, can be `random` `single` `circulation`(loop) `order`(no loop), default: `circulation`
|
||||
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
|
||||
listmaxheight: '513px', // Optional, max height of play list
|
||||
music: { // Required, music info, see: ###With playlist
|
||||
title: 'Preparation', // Required, music title
|
||||
author: 'Hans Zimmer/Richard Harvey', // Required, music author
|
||||
url: 'http://7xifn9.com1.z0.glb.clouddn.com/Preparation.mp3', // Required, music url
|
||||
pic: 'http://7xifn9.com1.z0.glb.clouddn.com/Preparation.jpg', // Optional, music picture
|
||||
lrc: '[00:00.00]lrc here\n[00:01.00]aplayer' // Optional, lrc, see: ###With lrc
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### API
|
||||
|
||||
+ `ap.play()` // Resume play
|
||||
+ `ap.play(time)` // Set currentTime
|
||||
+ `ap.pause()` // Pause
|
||||
+ `ap.toggle()` // Toggle between play and pause
|
||||
+ `ap.volume(percentage)` // Set volume
|
||||
+ `ap.on(event, handler)` // Event binding
|
||||
+ `ap.setMusic(index)` // Switch music
|
||||
+ `ap.lrc` // Lrc time and text
|
||||
+ `ap.playIndex` // Current playing index
|
||||
+ `ap.audio` // Return native video, most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
|
||||
+ `dp.audio.currentTime` // Returns the current playback position
|
||||
+ Most [native api](http://www.w3schools.com/tags/ref_av_dom.asp)
|
||||
|
||||
#### Event binding
|
||||
|
||||
`ap.on(event, handler)`
|
||||
|
||||
`event`:
|
||||
+ `play`: Triggered when APlayer start play
|
||||
+ `pause`: Triggered when APlayer paused
|
||||
+ `canplay`: Triggered when enough data is available that APlayer can be played
|
||||
+ `playing`: Triggered periodically when APlayer is playing
|
||||
+ `ended`: Triggered when APlayer ended
|
||||
+ `error`: Triggered when an error occurs
|
||||
|
||||
#### Work with module bundler
|
||||
|
||||
```js
|
||||
var APlayer = require('APlayer');
|
||||
var ap = new APlayer({
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
### With lrc
|
||||
|
||||
Show lrc, you can put LRC in JS or HTML as you like.
|
||||
|
||||
#### LRC format:
|
||||
|
||||
Support multiple time tag, support three decimal second
|
||||
|
||||
```
|
||||
[mm:ss.xx]lyric
|
||||
[mm:ss.xxx]lyric
|
||||
[mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
|
||||
...
|
||||
```
|
||||
|
||||
#### LRC in JS:
|
||||
|
||||
JS:
|
||||
|
||||
```js
|
||||
{
|
||||
showlrc: 1,
|
||||
music: {
|
||||
lrc: '[00:00.00]lrc here\n[00:01.00]aplayer' // lrc here, separate lines with \n
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### LRC in HTML:
|
||||
|
||||
JS:
|
||||
|
||||
```js
|
||||
{
|
||||
showlrc: 2
|
||||
}
|
||||
```
|
||||
|
||||
HTML:
|
||||
|
||||
```HTML
|
||||
<div id="player1" class="aplayer">
|
||||
<pre class="aplayer-lrc-content">
|
||||
[00:00.00]平凡之路 - 朴树
|
||||
[00:04.01]作词:韩寒 朴树
|
||||
[00:08.02]作曲:朴树 编曲:朴树
|
||||
[00:12.02]徘徊着的 在路上的
|
||||
[00:17.37]你要走吗
|
||||
[00:23.20]易碎的 骄傲着
|
||||
<!-- ... -->
|
||||
</pre>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### LRC in lrc file or API:
|
||||
|
||||
```js
|
||||
{
|
||||
showlrc: 3,
|
||||
music: {
|
||||
lrc: 'path/to/music.lrc'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### With playlist
|
||||
|
||||
Show multiple music.
|
||||
|
||||
#### JS:
|
||||
|
||||
Option:
|
||||
|
||||
```JS
|
||||
music: [
|
||||
{
|
||||
title: '',
|
||||
author: '',
|
||||
url: '',
|
||||
pic: ''
|
||||
},
|
||||
{
|
||||
title: '',
|
||||
author: '',
|
||||
url: '',
|
||||
pic: ''
|
||||
},
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
## Run in development
|
||||
|
||||
```
|
||||
$ npm install
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
## Make a release
|
||||
|
||||
```
|
||||
$ npm install
|
||||
$ npm run build
|
||||
```
|
||||
- [Telegram Group](https://t.me/adplayer)
|
||||
- [QQ Group](https://shang.qq.com/wpa/qunwpa?idkey=bf22213ae0028a82e5adf3f286dfd4f01e0997dc9f1dcd8e831a0a85e799be17): 415835947
|
||||
|
||||
## Related Projects
|
||||
|
||||
- [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin)
|
||||
### Plugins
|
||||
|
||||
- [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer)
|
||||
- [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin): Typecho
|
||||
- [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer): Hexo
|
||||
- [Hermit-X(APlayer for WordPress)](https://github.com/liwanglin12/Hermit-X): WordPress
|
||||
- [APlayerHandle](https://github.com/kn007/APlayerHandle): WordPress
|
||||
- [APlayer_for_Z-BlogPHP](https://github.com/fghrsh/APlayer_for_Z-BlogPHP): Z-BlogPHP
|
||||
- [react-aplayer](https://github.com/sabrinaluo/react-aplayer): React
|
||||
- [vue-aplayer](https://github.com/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
- [163music-APlayer-you-get-docker](https://github.com/YUX-IO/163music-APlayer-you-get-docker)
|
||||
### Tooling
|
||||
|
||||
- [Hermit-X(APlayer for WordPress)](https://github.com/liwanglin12/Hermit-X)
|
||||
- [APlayer-Controler](https://github.com/Mashiro-Sorata/APlayer-Controler): controling tool
|
||||
- [MetingJS](https://github.com/metowolf/MetingJS): work with Meting music API
|
||||
|
||||
## LICENSE
|
||||
## Who use APlayer?
|
||||
|
||||
[The Star And Thank Author License (SATA)](https://github.com/DIYgod/APlayer/blob/master/LICENSE)
|
||||
- [Jelly Rue](http://jellyrue.com/): Jelly Rue, an indie pop-rock band from Tartu.
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [iSearch](http://i.oppsu.cn): 一个提供 iTunes 搜索,试听,高清专辑封面获取,查看最新音乐动态等综合性平台
|
||||
- [LRC歌词编辑器](https://github.com/MoeFE/Lyric): 一款非常实用的在线LRC歌词编辑器
|
||||
- [Аэростатика](https://aerostatica.ru/)
|
||||
|
||||
## Donate
|
||||
|
||||
APlayer is an MIT licensed open source project and completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.
|
||||
|
||||
## One-time Donations
|
||||
|
||||
We accept donations through these channels:
|
||||
|
||||
- [Paypal](https://www.paypal.me/DIYgod)
|
||||
- [WeChat Pay](https://i.imgur.com/aq6PtWa.png)
|
||||
- [Alipay](https://i.imgur.com/wv1Pj2k.png)
|
||||
- Bitcoin: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1
|
||||
|
||||
## Recurring Pledges
|
||||
|
||||
Recurring pledges come with exclusive perks, e.g. having your name or your company logo listed in the APlayer GitHub repository and this website.
|
||||
|
||||
- Become a backer or sponsor via [OpenCollective](https://opencollective.com/aplayer)
|
||||
- E-mail us: i#html.love
|
||||
|
||||
## Current Premium Sponsors
|
||||
|
||||
### Special Sponsors
|
||||
|
||||
<a href="https://pear.hk/" target="_blank">
|
||||
<img width="222px" src="https://i.imgur.com/5qQYmfc.png">
|
||||
</a>
|
||||
<a href="https://console.upyun.com/register/?invite=BkLZ2Xqob" target="_blank">
|
||||
<img width="222px" src="https://imgur.com/apG1uKf.png">
|
||||
</a>
|
||||
|
||||
### OpenCollective backers
|
||||
|
||||

|
||||
|
||||
## Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
|
||||
<a href="https://github.com/MoePlayer/APlayer/graphs/contributors"><img src="https://opencollective.com/APlayer/contributors.svg?width=890" /></a>
|
||||
|
||||
## Author
|
||||
|
||||
**APlayer** © [DIYgod](https://github.com/DIYgod), Released under the [MIT](./LICENSE) License.<br>
|
||||
Authored and maintained by DIYgod with help from contributors ([list](https://github.com/DIYgod/APlayer/contributors)).
|
||||
|
||||
> [Blog](https://diygod.me) · GitHub [@DIYgod](https://github.com/DIYgod) · Twitter [@DIYgod](https://twitter.com/DIYgod) · Telegram Channel [@awesomeDIYgod](https://t.me/awesomeDIYgod)
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
var ap1 = new APlayer({
|
||||
const ap1 = new APlayer({
|
||||
element: document.getElementById('player1'),
|
||||
narrow: false,
|
||||
mini: false,
|
||||
autoplay: true,
|
||||
showlrc: false,
|
||||
lrc: false,
|
||||
mutex: true,
|
||||
theme: '#e6d0b2',
|
||||
preload: 'metadata',
|
||||
mode: 'circulation',
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'http://devtest.qiniudn.com/Preparation.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/Preparation.jpg'
|
||||
audio: {
|
||||
name: 'Preparation',
|
||||
artist: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
}
|
||||
});
|
||||
ap1.on('play', function () {
|
||||
@@ -36,99 +35,96 @@ ap1.on('error', function () {
|
||||
console.log('error');
|
||||
});
|
||||
|
||||
var ap2 = new APlayer({
|
||||
const ap2 = new APlayer({
|
||||
element: document.getElementById('player2'),
|
||||
narrow: true,
|
||||
mini: true,
|
||||
autoplay: false,
|
||||
showlrc: false,
|
||||
lrc: false,
|
||||
mutex: true,
|
||||
theme: '#e6d0b2',
|
||||
mode: 'circulation',
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'http://devtest.qiniudn.com/Preparation.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/Preparation.jpg'
|
||||
audio: {
|
||||
name: 'Preparation',
|
||||
artist: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
}
|
||||
});
|
||||
|
||||
var ap3 = new APlayer({
|
||||
const ap3 = new APlayer({
|
||||
element: document.getElementById('player3'),
|
||||
narrow: false,
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
showlrc: 3,
|
||||
lrc: 3,
|
||||
mutex: true,
|
||||
theme: '#615754',
|
||||
mode: 'circulation',
|
||||
music: {
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
url: 'http://devtest.qiniudn.com/回レ!雪月花.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/回レ!雪月花.jpg',
|
||||
lrc: "回レ!雪月花.lrc"
|
||||
audio: {
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
lrc: "https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc"
|
||||
}
|
||||
});
|
||||
|
||||
var ap4 = new APlayer({
|
||||
const ap4 = new APlayer({
|
||||
element: document.getElementById('player4'),
|
||||
narrow: false,
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
showlrc: false,
|
||||
lrc: false,
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
mode: 'random',
|
||||
music: [
|
||||
order: 'random',
|
||||
audio: [
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
author: '七森中☆ごらく部',
|
||||
url: 'http://devtest.qiniudn.com/あっちゅ~ま青春!.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/あっちゅ~ま青春!.jpg'
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
},
|
||||
{
|
||||
title: 'secret base~君がくれたもの~',
|
||||
author: '茅野愛衣',
|
||||
url: 'http://devtest.qiniudn.com/secret base~.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/secret base~.jpg'
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
},
|
||||
{
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
url: 'http://devtest.qiniudn.com/回レ!雪月花.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/回レ!雪月花.jpg'
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
var ap5 = new APlayer({
|
||||
const ap5 = new APlayer({
|
||||
element: document.getElementById('player5'),
|
||||
narrow: false,
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
showlrc: 3,
|
||||
lrc: 3,
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
mode: 'random',
|
||||
listmaxheight: '80px',
|
||||
music: [
|
||||
listFolded: true,
|
||||
audio: [
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
author: '七森中☆ごらく部',
|
||||
url: 'http://devtest.qiniudn.com/あっちゅ~ま青春!.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/あっちゅ~ま青春!.jpg',
|
||||
lrc: 'あっちゅ~ま青春!.lrc'
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.lrc'
|
||||
},
|
||||
{
|
||||
title: 'secret base~君がくれたもの~',
|
||||
author: '茅野愛衣',
|
||||
url: 'http://devtest.qiniudn.com/secret base~.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/secret base~.jpg',
|
||||
lrc: 'secret base~君がくれたもの~.lrc'
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.lrc'
|
||||
},
|
||||
{
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
url: 'http://devtest.qiniudn.com/回レ!雪月花.mp3',
|
||||
pic: 'http://devtest.qiniudn.com/回レ!雪月花.jpg',
|
||||
lrc: '回レ!雪月花.lrc'
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -43,26 +43,54 @@
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
<script src="APlayer.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<a href="https://github.com/DIYgod/APlayer" target="_blank" class="github-corner"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
|
||||
<div class="container">
|
||||
<h1>APlayer</h1>
|
||||
<h2>Wow, such a beautiful html5 music player</h2>
|
||||
<p>Made by <a href="https://www.anotherhome.net/" target="_blank">DIYgod</a>. Available on <a href="https://github.com/DIYgod/APlayer" target="_blank">GitHub</a>. Licensed MIT.</p>
|
||||
<hr>
|
||||
<h3>Normal</h3>
|
||||
<div id="player1" class="aplayer"></div>
|
||||
<h3>With lyrics</h3>
|
||||
<div id="player3" class="aplayer"></div>
|
||||
<div id="player1"></div>
|
||||
<p></p>
|
||||
<button onclick="ap1.play()">ap.play()</button>
|
||||
<button onclick="ap1.seek(100)">ap.seek(100)</button>
|
||||
<button onclick="ap1.pause()">ap.pause()</button>
|
||||
<button onclick="ap1.toggle()">ap.toggle()</button>
|
||||
<button onclick="ap1.volume(0.1)">ap.volume(0.1)</button>
|
||||
<button onclick="ap1.addAudio([
|
||||
{
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
},
|
||||
{
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
},
|
||||
{
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
}
|
||||
])">ap.addAudio(...)</button>
|
||||
<button onclick="ap1.destroy()">ap.destroy()</button>
|
||||
<h3>With playlist</h3>
|
||||
<div id="player4" class="aplayer"></div>
|
||||
<p></p>
|
||||
<button onclick="ap4.switchAudio(2)">ap.switchAudio(2)</button>
|
||||
<h3>With lyrics</h3>
|
||||
<div id="player3" class="aplayer"></div>
|
||||
<h3>With playlist and lyrics</h3>
|
||||
<div id="player5" class="aplayer"></div>
|
||||
<h3>Narrow</h3>
|
||||
<div id="player2" class="aplayer"></div>
|
||||
</div>
|
||||
<script src="../dist/APlayer.min.js"></script>
|
||||
<script src="demo.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,43 +0,0 @@
|
||||
[00:00.230]君と夏の終わり 将来の夢(与你在夏末约定 将来的梦想)
|
||||
[00:04.170]大きな希望 忘れない(远大的希望 不要忘记了)
|
||||
[00:07.170]10年後の8月(我相信 十年後的八月)
|
||||
[00:09.700]また出会えるのを 信じて(我们还能再相遇)
|
||||
[00:14.360]最高の思い出を…(共划美好的回忆)
|
||||
[00:39.960]出会いは ふっとした 瞬間 帰り道の交差点で(相识 是那麼不经意的瞬间 我在回家途中的十字路口)
|
||||
[00:47.050]声をかけてくれたね 「一緒に帰ろう」(听见你的一声〞一起回家吧〞)
|
||||
[00:54.310]僕は 照れくさそうに カバンで顔を隠しながら(我当时有点尴尬 还拿书包遮著脸)
|
||||
[01:01.470]本当は とても とても 嬉しかったよ(其实我 心里好高兴 真的好高兴)
|
||||
[01:08.590]あぁ 花火が夜空 きれいに咲いて ちょっとセツナク(啊!烟火在夜空中 灿烂盛开 几许伤感)
|
||||
[01:15.770]あぁ 風が時間とともに 流れる(啊!风随着时光流逝)
|
||||
[01:22.580]嬉しくって 楽しくって 冒険も いろいろしたね(满心欢喜地 兴致冲冲地 我们四处探险)
|
||||
[01:29.760]二人の 秘密の 基地の中(就在我们的 秘密基地中)
|
||||
[01:36.740]君と夏の終わり 将来の夢 大きな希望 忘れない(与你在夏末约定 将来的梦想 远大的希望 不要忘记了)
|
||||
[01:43.920]10年後の8月 また出会えるのを 信じて(我相信 十年後的八月 我们还能再相遇)
|
||||
[01:51.010]君が最後まで 心から 「ありがとう」叫んでいたこと(我知道 一直到最後)
|
||||
[01:56.930]知っていたよ(你仍在心底呼喊著〞谢谢你〞)
|
||||
[01:58.200]涙をこらえて 笑顔でさようなら せつないよね(强忍著泪水 笑著说再见 无限感叹涌现)
|
||||
[02:05.420]最高の思い出を…(那一段最美好的回忆…)
|
||||
[02:13.070]あぁ 夏休みも あと少しで 終っちゃうから(啊!暑假就快要过完了)
|
||||
[02:20.310]あぁ 太陽と月 仲良くして(啊!太阳和月亮 默契十足)
|
||||
[02:27.080]悲しくって 寂しくって 喧嘩も いろいろしたね(想到令人悲伤 或许有些寂寥 我们也多有争吵)
|
||||
[02:34.160]二人の 秘密の 基地の中(就在我们的 秘密基地中)
|
||||
[02:41.140]君が最後まで 心から 「ありがとう」叫んでいたこと(我知道 一直到最後)
|
||||
[02:47.000]知っていたよ(你仍在心底呼喊著〞谢谢你)
|
||||
[02:48.340]涙をこらえて 笑顔でさようなら せつないよね(强忍著泪水 笑著说再见 无限感叹涌现)
|
||||
[02:55.630]最高の思い出を…(那一段最美好的回忆)
|
||||
[03:03.320]突然の 転校で どうしようもなく(你突然要转学 你我都可奈何)
|
||||
[03:24.190]手紙 書くよ 電話もするよ 忘れないでね 僕のことを(我会写信给你 也会打电话给你 千万不要忘记我)
|
||||
[03:31.420]いつまでも 二人の 基地の中(永远别忘记 那段在秘密基地中的日子)
|
||||
[03:38.520]君と夏の終わり ずっと話して(与你在夏末 聊了这麼多)
|
||||
[03:42.530]夕日を見てから星を眺め(从黄昏到繁星点点)
|
||||
[03:45.670]君の頬を 流れた涙は ずっと忘れない(流过你双颊的泪水 我永远不会忘记)
|
||||
[03:52.820]君が最後まで 大きく手を振ってくれたこと(直到最後 你紧紧握住我的手 这感觉也将长在我心中)
|
||||
[03:58.540]きっと忘れない(於是就这样)
|
||||
[03:59.930]だから こうして 夢の中で ずっと永遠に…(让我们在梦中相会吧 永远的…)
|
||||
[04:07.110]君と夏の終わり 将来の夢 大きな希望 忘れない(与你在夏末约定 将来的梦想 远大的希望 不要忘记了)
|
||||
[04:14.270]10年後の8月 また出会えるのを 信じて(我相信 十年後的八月 我们还能再相遇)
|
||||
[04:21.400]君が最後まで 心から 「ありがとう」叫んでいたこと(我知道 一直到最後)
|
||||
[04:27.260]知っていたよ(你仍在心底呼喊著〞谢谢你〞)
|
||||
[04:28.640]涙をこらえて 笑顔でさようなら せつないよね(强忍著泪水 笑著说再见 无限感叹涌现)
|
||||
[04:35.910]最高の思い出を…(那一段最美好的回忆…)
|
||||
[04:43.160]最高の思い出を…(那一段最美好的回忆…)
|
||||
@@ -1,51 +0,0 @@
|
||||
[ti:あっちゅ~ま青春!]
|
||||
[ar:七森中☆ごらく部]
|
||||
[al:あっちゅ~ま青春!]
|
||||
[00:00.76]青春オーライ 青春オーエス 青春謳歌 はりきって行くぞ(青春 All right 青春 Oh Hisse 青春讴歌 鼓足干劲上吧!)
|
||||
[00:05.96]青春ドンマイ 青春ファイト 青春最高(青春 Don't Mind 青春 Fight 青春最棒了!)
|
||||
[00:09.67]Yeah!! Yeah!! Yeah!! Yeah!!
|
||||
[00:12.21]青春はじめよう 1・2・さん☆ハイ!(让青春起步吧! 1·2·三☆OK!)
|
||||
[00:14.78]ひとまず走るぞ 1・2・さん☆ハイ!(不管如何先跑起来吧! 1·2·三☆OK!)
|
||||
[00:17.32]みんなが笑顔で 1・2・さん☆ハイ!(大家都露出笑脸! 1·2·三☆OK!)
|
||||
[00:19.95]これが青春だ 1・2・さん☆ハイ!(这就是青春! 1·2·三☆OK!)
|
||||
[00:22.71]春! 桜もちを食べよう 夏! かき氷で決まり(春天! 来吃樱叶饼吧 夏天! 就决定是刨冰啦)
|
||||
[00:27.89]秋! 焼きいもを頬張り 冬! 雪でまたかき氷(秋天! 把烤白薯大口塞进嘴里 冬天! 在雪里面又是刨冰)
|
||||
[00:32.57]もういっちょ☆(再来☆)
|
||||
[00:33.16]春! 教室を間違えて 夏! 宿題を忘れて(春天! 进错了教室 夏天! 把作业忘掉了)
|
||||
[00:38.37]秋! マラソンでビリケツ 冬! こたつに長期滞在(秋天! 马拉松最后一名 冬天! 长期居住在暖炉里)
|
||||
[00:43.61]1年365日 ときどき366日(一年中的365天 有时候是366天)
|
||||
[00:48.69]色々あるけど 全力!全開! 全身全霊! 楽しもうよ よーよよよよ(虽然会发生很多事情,但是一起尽力尽兴!全心全意!享受每一天吧!吧~吧吧吧吧)
|
||||
[00:55.23]「えんじょい!えんじょい!じょじょじょじょじょい!」(「享受吧!享受吧! 吧吧吧吧吧!」)
|
||||
[00:57.83]あっちゅ~ま青春! まぶし~いよ青春!(转瞬即逝的青春! 灿烂无比的青春!)
|
||||
[01:03.17]眠気さよなら ココロの瞳をぱっちりあけよう(向困意说拜拜 把心灵的眼睛睁得大大的吧)
|
||||
[01:08.42]あっちゅ~ま青春! 猛スピード青春!(转瞬即逝的青春! 飞速前进的青春!)
|
||||
[01:13.64]まばたきしてちゃ おいしいところ見逃しちゃうよ 注意!(要是乱眨眼睛的话 就会把美味的时光错过了的啦! 要注意哦!)
|
||||
[01:18.87]青春オーライ 青春オーエス 青春謳歌 はりきって行くぞ(青春 All right 青春 Oh Hisse 青春讴歌 鼓足干劲上吧!)
|
||||
[01:24.17]青春ドンマイ 青春ファイト 青春最高(青春 Don't Mind(别在意) 青春 Fight(奋斗) 青春最棒了!)
|
||||
[01:27.85]Yeah!! Yeah!! Yeah!! Yeah!!
|
||||
[01:30.44]朝! ニワトリに追いかけられ 昼! まさかのテスト0点(早上!被鸡到处追着跑 中午! 考试没想到竟然零分!)
|
||||
[01:35.72]放課後! みんなに励まされて 夜! 今日は寝て忘れましょう(放学后! 大家给我加油 晚上!今天就睡觉把烦恼忘掉吧!)
|
||||
[01:40.35]次の日~っ☆(第二天~☆)
|
||||
[01:40.84]朝! ぎりぎり社長出勤 昼! 給食をおかわり(早上!差点就迟到了 中午!食堂的饭再来一份)
|
||||
[01:46.10]放課後! 部室でダラダララ~ 夜! 長電話止まらない(放学后! 在部团教室懒散度过 晚上! 煲电话粥停不下来)
|
||||
[01:51.32]1日いつでも24時間 巻くこと押すことどちらもできない(一天永远都是24小时 既不会提前也不会延后)
|
||||
[01:56.52]やりたいことなら貪欲強欲 別腹パッパラやり尽そうよ よーよよよよ(如果是想做的事情的话 就要贪婪地去追求 开启第二个胃 去把所有想干的事情都做了吧!)
|
||||
[02:02.95]「わっしょい!わっしょい!しょしょしょしょしょい!」(「欧耶! 欧耶! 耶耶耶耶耶!」)
|
||||
[02:05.58]あっちゅ~ま青春! 楽し~いよ青春!(转瞬即逝的青春! 快乐无比的青春!)
|
||||
[02:11.06]春に始まり春に向かってく 思い出つくろう(开始在春天的青春 为了这个春天 一起创造回忆吧)
|
||||
[02:16.23]あっちゅ~ま青春! 青い春だ青春!(转瞬即逝的青春! 青色的春天就是……青春!)
|
||||
[02:21.40]ブルーなキモチ みんなといるとカラフルになる 不思議!(那些忧郁的心情 只要和大家在一起就会变得色彩缤纷 真是不可思议!)
|
||||
[02:26.82]青春オーライ 青春オーエス 青春謳歌 はりきって行くぞ(青春 All right 青春 Oh Hisse 青春讴歌 鼓足干劲上吧!)
|
||||
[02:31.99]青春ドンマイ 青春ファイト 青春最高(青春 Don't Mind 青春 Fight 青春最棒了!)
|
||||
[02:35.68]Yeah!! Yeah!! Yeah!! Yeah!!
|
||||
[02:47.61]あっちゅ~ま青春! まぶし~いよ青春!(转瞬即逝的青春! 灿烂无比的青春!)
|
||||
[02:52.67]眠気さよなら ココロの瞳をぱっちりあけよう(向困意说拜拜 把心灵的眼睛睁得大大的吧)
|
||||
[02:58.01]あっちゅ~ま青春! 猛スピード青春!(转瞬即逝的青春! 飞速前进的青春!)
|
||||
[03:03.22]まばたきしてちゃ おいしいところ見逃しちゃうよ 注意!(要是乱眨眼睛的话 就会把美味的时光错过了的啦! 要注意哦!)
|
||||
[03:08.56]あっちゅ~ま青春! にぎや~かな青春!(转瞬即逝的青春! 热热闹闹的青春!)
|
||||
[03:13.68]今が青春 感じられた日はステキな日だよ(现在就是能感受到青春的 最棒的日子哦)
|
||||
[03:18.86]あっちゅ~ま青春! 二度と来ない青春!(转瞬即逝的青春! 一去不复返的青春!)
|
||||
[03:24.07]気付けばいつも私の青春 キミがいるんだ キ・セ・キ(回过神来 在我的青春中都有你在身边 真・是・奇・迹)
|
||||
[03:29.41]青春オーライ 青春オーエス 青春謳歌 はりきって行くぞ(青春 All right 青春 Oh Hisse 青春讴歌 鼓足干劲上吧!)
|
||||
[03:34.56]青春ドンマイ 青春ファイト 青春最高(青春 Don't Mind 青春 Fight 青春最棒了!)
|
||||
[03:38.23]Yeah!! Yeah!! Yeah!! Yeah!!
|
||||
@@ -1,91 +0,0 @@
|
||||
[by:京兆万年]
|
||||
[ti:回レ!雪月花 小紫ver.]
|
||||
[ar:小倉唯]
|
||||
[lr:ヒゲドライバー]
|
||||
[co:ヒゲドライバー]
|
||||
[ag:ヒゲドライバー]
|
||||
[00:00.00]せ〜の いちにっさんはい!(预~备 一 二 三 嗨!)
|
||||
[00:04.68]ほい! いよーーーーっ ぽん!(嘿 咿哟 嘭)
|
||||
[00:07.66]ハッハッハッハッハッハッハィヤ(哈 哈 哈 哈 哈 哈 嗨呀)
|
||||
[00:11.12]ハッハッハッハッハッハッ う~(哈 哈 哈 哈 哈 哈 呜~)
|
||||
[00:13.36]さぁさぁさぁ(来 来 来)
|
||||
[00:14.08]これよりご覧いただきますは(接下来诸位将欣赏到的是)
|
||||
[00:15.65]カブキ者たちの栄枯盛衰(歌舞伎演员们的荣辱盛衰)
|
||||
[00:17.14]時代常に日進月歩(时代总是在日新月异)
|
||||
[00:18.24]聞いてってよ老若男女(且听我一一道来 男女老少)
|
||||
[00:20.14]一見は勧善懲悪(乍一看是惩恶扬善)
|
||||
[00:21.49]悪者どもを一刀両断(将坏人们一刀两断)
|
||||
[00:22.85]「でもホンドにそれだけで楽しいの?」(“但是你真的会因此而觉得扬眉吐气吗?”)
|
||||
[00:25.63]もうなんだって蒟蒻問答(无论问什么 都是牛头马嘴)
|
||||
[00:27.58]ハッハッハッハッハッハッハィヤ(哈哈哈哈哈哈 咿呀)
|
||||
[00:30.57]ハッハッハッハッ(哈哈哈哈)
|
||||
[00:31.97]いよーーーーっ ぽん!(咿哟 嘭)
|
||||
[00:33.61]どこからともなく現れて(自何处出现委实难料)
|
||||
[00:34.96]すぐどこかへ行っちゃって神出鬼沒(眼又遁隐他处总是神出鬼没)
|
||||
[00:36.35]チャンスを待ったら一日千秋(若是静候机会 便是一日千秋)
|
||||
[00:38.03]追いかければ東奔西走(追上前去的话又要东奔西走)
|
||||
[00:39.68]時代常に千変万化(时代总是千变万化)
|
||||
[00:40.95]人の心は複雑怪奇(世人之心复杂怪奇)
|
||||
[00:42.31]「でも本気でそんなこ言ってんの?」(“但是说着这些话的你岂不也是难免戏谑?”)
|
||||
[00:45.02]もうどうにも満身創痍(也罢 无论怎样都将满身疮痍)
|
||||
[00:46.98]嗚呼、巡り巡って夜の町(呜呼 绕来绕去相会在这夜色下的街)
|
||||
[00:53.27]キミは合図出し踊りだす((由)你发出信号 (让)我们一同起舞转)
|
||||
[00:58.12]はぁ~(哈呜~)
|
||||
[00:58.88]回レ回レ回レ回レ回レ回レ回レ回レ回レ!(旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧!)
|
||||
[01:02.12]華麗に花弁 散らすように(在散落的美丽花瓣中)
|
||||
[01:04.97]回レ回レ回レ回レ回レ回レ回レ回レ回レ!(旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧旋转吧!)
|
||||
[01:08.13]髪も振り乱して(头发凌乱又怎样?)
|
||||
[01:10.23]一昨日、昨日、今日と、明日と、明後日と(前日、昨日、今日、明日、后日)
|
||||
[01:14.13]この宴は続く(这场宴会亦不息)
|
||||
[01:16.31]踊レ、歌エ、一心不乱に回レ!(舞动吧 歌唱吧 一心不乱的旋转吧于)
|
||||
[01:20.19]今宵は雪月花(今夜的雪月花)
|
||||
[01:25.43]ほい! いよーーーーっ ぽん!(哈~!~哟ーーーー~嘣~!)
|
||||
[01:29.14]ハッハッハッハッハッハッハィヤ(哈 哈 哈 哈 哈 哈 嗨呀)
|
||||
[01:32.16]ハッハッハッハッハッハッ う~(哈 哈 哈 哈 哈 哈 呜)
|
||||
[01:34.39]ねぇねぇねぇ(呐~呐~呐~)
|
||||
[01:35.12]この世に平安訪れるの?(平安已经访问此世了吗?)
|
||||
[01:36.50]のべつ幕無し丁丁発止(不会闭幕的丁当争斗)
|
||||
[01:38.09]兵ども千客万来(官兵们接踵而来)
|
||||
[01:39.50]ひしめき合群雄割拠(相互吵吵嚷嚷群雄割据)
|
||||
[01:41.00]伸るか反るか一攫千金(成败在于敢否一举千金)
|
||||
[01:42.47]気が付いたら絶体絶命(回过头来却已穷途末路)
|
||||
[01:43.50]「でも本音のとこ、どうなってんの?」(「不过真心的所在、到底是什么样呢?」)
|
||||
[01:46.62]もうまったく奇想天外(真是的总这么异想天开)
|
||||
[01:48.51]嗚呼、辿り辿って夜の町(呜呼、追溯于夜晚小镇上)
|
||||
[01:54.83]迷い一つなく踊りだす(心无杂念的就此起舞吧)
|
||||
[01:59.68]はぁ~(哈阿~)
|
||||
[02:00.44]回レ回レ回レ回レ回レ 回レ回レ回レ回レ!(转啊转啊转啊转啊转啊转啊转啊转啊转啊!)
|
||||
[02:03.64]華麗に花弁 散らすように(犹如花瓣华丽的散落一般)
|
||||
[02:06.49]回レ回レ回レ回レ回レ 回レ回レ回レ回レ!(转啊转啊转啊转啊转啊转啊转啊转啊转啊!)
|
||||
[02:09.66]髪も振り乱して(长发也随风飘散)
|
||||
[02:11.72]一昨日、昨日、今日と、明日と、明後日と(无论前天、昨天、还是今天、明天、与后天)
|
||||
[02:15.63]この宴は続く(这宴会还会持续)
|
||||
[02:17.67]踊レ、歌エ、一心不乱に回レ!(跳吧、唱吧、一心一意的转吧!)
|
||||
[02:21.60]今宵は雪月花(因为今宵乃是雪月花)
|
||||
[02:36.74]ハッハッハッハッハッハッハィヤ(哈 哈 哈 哈 哈 哈 嗨呀)
|
||||
[02:39.72]ハッハッハッハッハッハッ さぁさぁさぁ(哈 哈 哈 哈 哈 哈 来~来~来~)
|
||||
[02:42.45]ハッハッハッハッハッハッハィヤ(哈 哈 哈 哈 哈 哈 嗨呀)
|
||||
[02:45.49]ハッハッハッハッハッハッ(哈 哈 哈 哈 哈 哈)
|
||||
[02:47.66]花で一つ、鳥で二つ(花就是一、鸟就是二)
|
||||
[02:51.31]手打ち鳴らす(拍着手轻声唱)
|
||||
[02:54.12]風で三つ、嗚呼、月出て四つ(风就是三、呜呼、月出就有四)
|
||||
[02:58.76]鳴らす鳴らす……(轻声唱轻轻唱……)
|
||||
[03:00.09]花で一つ、鳥で二つ(花就是一、鸟就是二)
|
||||
[03:03.34]手打ち鳴らす(拍着手轻声唱)
|
||||
[03:06.25]風で三つ、嗚呼、月出て四つ(风就是三、呜呼、月出就有四)
|
||||
[03:10.78]鳴らす鳴らす……(轻轻唱轻声唱……)
|
||||
[03:13.28]今は(在此)
|
||||
[03:15.35]回レ回レ回レ回レ回レ 回レ回レ回レ回レ!(转啊转啊转啊转啊转啊转啊转啊转啊转啊!)
|
||||
[03:18.63]華麗に花弁 散らすように(犹如花瓣华丽的散落一般)
|
||||
[03:21.35]回レ回レ回レ回レ回レ 回レ回レ回レ回レ!(转啊转啊转啊转啊转啊转啊转啊转啊转啊!)
|
||||
[03:24.60]髪も振り乱して(长发也随风飘散)
|
||||
[03:26.72]一昨日、昨日、今日と、明日と、明後日と(无论前天、昨天、还是今天、明天、与后天)
|
||||
[03:30.67]この宴は続く(这宴会不会结束)
|
||||
[03:32.75]踊レ、歌エ、一心不乱に回レ!(跳吧、唱吧、一心一意的转吧!)
|
||||
[03:36.63]今宵は何曜日か?(今宵是星期几呢?)
|
||||
[03:39.02]水木金?(三四五?)
|
||||
[03:40.56]土日月火?(六七一二?)
|
||||
[03:44.11]ハッハッハッハッハッハッハィヤ(哈 哈 哈 哈 哈 哈 嗨呀)
|
||||
[03:47.00]ハッハッハッハッ(哈 哈 哈 哈 哈 哈)
|
||||
[03:48.57]いよーーーーっ ぽん!(~哟ーーーー~嘣~!)
|
||||
[03:50.43]-終わり-(-End-)
|
||||
@@ -0,0 +1 @@
|
||||
aplayer.js.org
|
||||
@@ -0,0 +1,398 @@
|
||||
---
|
||||
search: english
|
||||
---
|
||||
|
||||
# APlayer
|
||||
|
||||
🍭 Wow, such a beautiful HTML5 music player
|
||||
|
||||
## Special Sponsors
|
||||
|
||||
<a href="https://pear.hk/" target="_blank">
|
||||
<img width="222px" src="https://i.imgur.com/5qQYmfc.png">
|
||||
</a>
|
||||
<a href="https://www.upyun.com/" target="_blank">
|
||||
<img width="222px" src="https://imgur.com/apG1uKf.png">
|
||||
</a>
|
||||
|
||||
## Installation
|
||||
|
||||
Using npm:
|
||||
|
||||
```
|
||||
npm install aplayer --save
|
||||
```
|
||||
|
||||
Using Yarn:
|
||||
|
||||
```
|
||||
yarn add aplayer
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer2"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
<div id="aplayer"></div>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
Work with module bundler:
|
||||
|
||||
```js
|
||||
import 'APlayer/dist/APlayer.min.css';
|
||||
import APlayer from 'APlayer';
|
||||
|
||||
const ap = new APlayer(options);
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
Name | Default | Description
|
||||
----|-------|----
|
||||
container | document.querySelector('.aplayer') | player container
|
||||
mini | false | enable mini mode, [see more details](https://aplayer.js.org/#/home?id=mini-mode)
|
||||
autoplay | false | audio autoplay
|
||||
theme | '#b7daff' | main color
|
||||
loop | 'all' | player loop play, values: 'all', 'one', 'none'
|
||||
order | 'list' | player play order, values: 'list', 'random'
|
||||
preload | 'auto' | values: 'none', 'metadata', 'auto'
|
||||
volume | 0.7 | default volume, notice that player will remember user setting, default volume will not work after user set volume themselves
|
||||
audio | - | audio info, should be an object or object array
|
||||
audio.name | - | audio name
|
||||
audio.artist | - | audio artist
|
||||
audio.url | - | audio url
|
||||
audio.cover | - | audio cover
|
||||
audio.lrc | - | [see more details](https://aplayer.js.org/#/home?id=lrc)
|
||||
mutex | true | prevent to play multiple player at the same time, pause other players when this player start play
|
||||
lrc | false | [see more details](https://aplayer.js.org/#/home?id=lrc)
|
||||
listFolded | false | indicate whether list should folded at first
|
||||
listMaxHeight | - | list max height
|
||||
|
||||
For example:
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer3"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
theme: '#FADFA3',
|
||||
loop: 'all',
|
||||
order: 'random',
|
||||
preload: 'auto',
|
||||
volume: 0.7,
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg',
|
||||
lrc: 'lrc1.lrc'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg',
|
||||
lrc: 'lrc2.lrc'
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
+ `ap.play()`: play audio
|
||||
|
||||
+ `ap.pause()`: pause audio
|
||||
|
||||
+ `ap.seek(time: number)`: seek to specified time
|
||||
|
||||
```js
|
||||
ap.seek(100);
|
||||
```
|
||||
|
||||
+ `ap.toggle()`: toggle between play and pause
|
||||
|
||||
+ `ap.on(event: string, handler: function)`: bind audio and player events, [see more details](https://aplayer.js.org/#/home?id=event-binding)
|
||||
|
||||
+ `ap.switchAudio(index: number)`: switch audio list
|
||||
|
||||
```js
|
||||
ap.switchAudio(1);
|
||||
```
|
||||
|
||||
+ `ap.addAudio(audio)`: add new audios to the list
|
||||
|
||||
```js
|
||||
ap.addAudio([
|
||||
{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
lrc: 'lrc.lrc'
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
+ `ap.removeAudio(index: number)`: remove audio from the list
|
||||
|
||||
```js
|
||||
ap.removeAudio(1);
|
||||
```
|
||||
|
||||
+ `ap.volume(percentage: number, nostorage: boolean)`: set audio volume
|
||||
|
||||
```js
|
||||
ap.volume(0.1, true);
|
||||
```
|
||||
|
||||
+ `ap.destroy()`: destroy player
|
||||
|
||||
+ `ap.audio`: native audio
|
||||
|
||||
+ `ap.audio.currentTime`: returns the current playback position
|
||||
|
||||
+ `ap.audio.duration`: returns audio total time
|
||||
|
||||
+ `ap.audio.paused`: returns whether the audio paused
|
||||
|
||||
+ most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
|
||||
|
||||
## Event binding
|
||||
|
||||
`ap.on(event, handler)`
|
||||
|
||||
```js
|
||||
ap.on('ended', function () {
|
||||
console.log('player ended');
|
||||
});
|
||||
```
|
||||
|
||||
Video events
|
||||
|
||||
- abort
|
||||
- canplay
|
||||
- canplaythrough
|
||||
- durationchange
|
||||
- emptied
|
||||
- ended
|
||||
- error
|
||||
- loadeddata
|
||||
- loadedmetadata
|
||||
- loadstart
|
||||
- mozaudioavailable
|
||||
- pause
|
||||
- play
|
||||
- playing
|
||||
- progress
|
||||
- ratechange
|
||||
- seeked
|
||||
- seeking
|
||||
- stalled
|
||||
- suspend
|
||||
- timeupdate
|
||||
- volumechange
|
||||
- waiting
|
||||
|
||||
Player events
|
||||
|
||||
- switchaudio
|
||||
- addaudio
|
||||
- removeaudio
|
||||
- destroy
|
||||
|
||||
## LRC
|
||||
|
||||
We have three ways to pass LRC to APlayer, indicate the way to pass LRC by option `lrc`, then put lrc to option `audio.lrc` or HTML.
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer4"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
### LRC file
|
||||
|
||||
The first way, put LRC to a LRC file, LRC file will be loaded when this audio start to play.
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 3,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'demo.mp3',
|
||||
cover: 'demo.jpg',
|
||||
lrc: 'lrc.lrc'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### LRC string in JS
|
||||
|
||||
The second way, put LRC to a JS string.
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 1,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'demo.mp3',
|
||||
cover: 'demo.jpg',
|
||||
lrc: '[00:00.00]APlayer\n[00:04.01]is\n[00:08.02]amazing'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### LRC in HTML
|
||||
|
||||
The third way, put LRC to HTML.
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
<div id="player">
|
||||
<pre class="aplayer-lrc-content">
|
||||
[00:00.00]APlayer audio1
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
<!-- ... -->
|
||||
</pre>
|
||||
<pre class="aplayer-lrc-content">
|
||||
[00:00.00]APlayer audio2
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
<!-- ... -->
|
||||
</pre>
|
||||
</div>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 2,
|
||||
audio: [[
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg'
|
||||
}
|
||||
]]
|
||||
});
|
||||
```
|
||||
|
||||
### LRC format
|
||||
|
||||
The following LRC format are supported:
|
||||
|
||||
`[mm:ss]APlayer`
|
||||
|
||||
`[mm:ss.xx]is`
|
||||
|
||||
`[mm:ss.xxx]amazing`
|
||||
|
||||
`[mm:ss.xx][mm:ss.xx]APlayer`
|
||||
|
||||
`[mm:ss.xx]<mm:ss.xx>is`
|
||||
|
||||
`[mm:ss.xx]amazing[mm:ss.xx]APlayer`
|
||||
|
||||
## Playlist
|
||||
|
||||
APlayer will show a playlist when it has more than one audio, option `listFolded` indicates whether list should folded at first, and option `listMaxHeight` indicates list max height.
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer5"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg',
|
||||
lrc: 'lrc1.lrc'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg',
|
||||
lrc: 'lrc2.lrc'
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
## Mini mode
|
||||
|
||||
If you don't have enough space for normal player, mini mode might be your choice.
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer6"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
mini: true,
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
## CDN
|
||||
|
||||
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
|
||||
- [cdnjs](https://cdnjs.com/libraries/aplayer)
|
||||
- [unpkg](https://unpkg.com/aplayer/)
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why can't player autoplay in some mobile browsers?
|
||||
|
||||
Most mobile browsers forbid video autoplay, you wont be able to achieve it without hacks.
|
||||
@@ -0,0 +1,208 @@
|
||||
const langs = [
|
||||
{ title: 'English', path: '/home', matchPath: /^\/(home|ecosystem|support)/ },
|
||||
{ title: '简体中文', path: '/zh-Hans/', matchPath: /^\/zh-Hans/ },
|
||||
];
|
||||
|
||||
docute.init({
|
||||
landing: 'landing.html',
|
||||
title: 'APlayer',
|
||||
repo: 'DIYgod/APlayer',
|
||||
twitter: 'DIYgod',
|
||||
'edit-link': 'https://github.com/MoePlayer/APlayer/tree/master/docs',
|
||||
nav: {
|
||||
default: [
|
||||
{
|
||||
title: 'Home', path: '/home'
|
||||
},
|
||||
{
|
||||
title: 'Ecosystem', path: '/ecosystem'
|
||||
},
|
||||
{
|
||||
title: 'Support APlayer', path: '/support'
|
||||
},
|
||||
{
|
||||
title: 'Languages', type: 'dropdown', items: langs
|
||||
}
|
||||
],
|
||||
'zh-Hans': [
|
||||
{
|
||||
title: '首页', path: '/zh-Hans/'
|
||||
},
|
||||
{
|
||||
title: '生态', path: '/zh-Hans/ecosystem'
|
||||
},
|
||||
{
|
||||
title: '支持 APlayer', path: '/zh-Hans/support'
|
||||
},
|
||||
{
|
||||
title: '选择语言', type: 'dropdown', items: langs
|
||||
}
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
docsearch({
|
||||
apiKey: '',
|
||||
indexName: 'aplayer',
|
||||
tags: ['english', 'zh-Hans'],
|
||||
url: 'https://aplayer.js.org'
|
||||
}),
|
||||
evanyou(),
|
||||
player()
|
||||
]
|
||||
});
|
||||
|
||||
function player () {
|
||||
return function (context) {
|
||||
context.event.on('landing:updated', function () {
|
||||
console.log('landing:updated');
|
||||
clearPlayer();
|
||||
aplayer1();
|
||||
});
|
||||
context.event.on('content:updated', function () {
|
||||
console.log('content:updated');
|
||||
clearPlayer();
|
||||
for (let i = 0; i < document.querySelectorAll('.load').length; i++) {
|
||||
document.querySelectorAll('.load')[i].addEventListener('click', function () {
|
||||
window[this.parentElement.id] && window[this.parentElement.id]();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function clearPlayer () {
|
||||
for (let i = 1; i < 10; i++) {
|
||||
if (window['dp' + (i + 1)]) {
|
||||
window['dp' + (i + 1)].destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function aplayer1 () {
|
||||
window.ap1 = new APlayer({
|
||||
container: document.getElementById('aplayer1'),
|
||||
theme: '#F57F17',
|
||||
lrc: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc'
|
||||
}, {
|
||||
name: 'トリカゴ',
|
||||
artist: 'XX:me',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.lrc'
|
||||
}, {
|
||||
name: '前前前世',
|
||||
artist: 'RADWIMPS',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer2 () {
|
||||
window.ap2 = new APlayer({
|
||||
container: document.getElementById('aplayer2'),
|
||||
theme: '#e6d0b2',
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer3 () {
|
||||
window.ap3 = new APlayer({
|
||||
container: document.getElementById('aplayer3'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
theme: '#FADFA3',
|
||||
loop: 'all',
|
||||
order: 'random',
|
||||
preload: 'auto',
|
||||
volume: 0.7,
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc'
|
||||
}, {
|
||||
name: 'トリカゴ',
|
||||
artist: 'XX:me',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.lrc'
|
||||
}, {
|
||||
name: '前前前世',
|
||||
artist: 'RADWIMPS',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer4 () {
|
||||
window.ap4 = new APlayer({
|
||||
container: document.getElementById('aplayer4'),
|
||||
lrc: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
lrc: "https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc"
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer5 () {
|
||||
window.ap5 = new APlayer({
|
||||
container: document.getElementById('aplayer5'),
|
||||
lrc: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc'
|
||||
}, {
|
||||
name: 'トリカゴ',
|
||||
artist: 'XX:me',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.lrc'
|
||||
}, {
|
||||
name: '前前前世',
|
||||
artist: 'RADWIMPS',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer6 () {
|
||||
window.ap6 = new APlayer({
|
||||
container: document.getElementById('aplayer6'),
|
||||
mini: true,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
}]
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
search: english
|
||||
---
|
||||
|
||||
# Ecosystem
|
||||
|
||||
Let's make APlayer better, feel free to submit yours in [`Let me know!`](https://github.com/MoePlayer/APlayer/issues/79)
|
||||
|
||||
## Help
|
||||
|
||||
### Joining the Discussion
|
||||
|
||||
- [Telegram Group](https://t.me/adplayer)
|
||||
- [QQ Group](https://shang.qq.com/wpa/qunwpa?idkey=bf22213ae0028a82e5adf3f286dfd4f01e0997dc9f1dcd8e831a0a85e799be17): 415835947
|
||||
|
||||
### Creating issue
|
||||
|
||||
- [MoePlayer/APlayer/issues](https://github.com/MoePlayer/APlayer/issues)
|
||||
|
||||
## Related Projects
|
||||
|
||||
### Plugins
|
||||
|
||||
- [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin): Typecho
|
||||
- [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer): Hexo
|
||||
- [Hermit-X(APlayer for WordPress)](https://github.com/liwanglin12/Hermit-X): WordPress
|
||||
- [APlayerHandle](https://github.com/kn007/APlayerHandle): WordPress
|
||||
- [APlayer_for_Z-BlogPHP](https://github.com/fghrsh/APlayer_for_Z-BlogPHP): Z-BlogPHP
|
||||
- [react-aplayer](https://github.com/sabrinaluo/react-aplayer): React
|
||||
- [vue-aplayer](https://github.com/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
### Tooling
|
||||
|
||||
- [APlayer-Controler](https://github.com/Mashiro-Sorata/APlayer-Controler): controling tool
|
||||
- [MetingJS](https://github.com/metowolf/MetingJS): work with Meting music API
|
||||
|
||||
## Who use APlayer?
|
||||
|
||||
- [Jelly Rue](http://jellyrue.com/): Jelly Rue, an indie pop-rock band from Tartu.
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [iSearch](http://i.oppsu.cn): 一个提供 iTunes 搜索,试听,高清专辑封面获取,查看最新音乐动态等综合性平台
|
||||
- [LRC歌词编辑器](https://github.com/MoeFE/Lyric): 一款非常实用的在线LRC歌词编辑器
|
||||
- [Аэростатика](https://aerostatica.ru/)
|
||||
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
|
||||
<title>APlayer</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docute/dist/docute.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docute/dist/theme-github.css" />
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-48084758-8"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag() { dataLayer.push(arguments); }
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'UA-48084758-8');
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
text-rendering: auto;
|
||||
}
|
||||
#evanyou-canvas {
|
||||
z-index: -1 !important;
|
||||
}
|
||||
.aplayer-wrap {
|
||||
max-width: 700px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- don't remove this part start -->
|
||||
<div id="app"></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/docute/plugins/docsearch.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/docute-evanyou/dist/evanyou.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/docute/dist/docute.js"></script>
|
||||
<script src="./config.js"></script>
|
||||
<!-- livereload script placeholder -->
|
||||
<!-- don't remove this part end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,83 @@
|
||||
<h1>APlayer</h1>
|
||||
|
||||
<h3>🍭 Wow, such a beautiful HTML5 music player.</h3>
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer1"></div>
|
||||
</div>
|
||||
|
||||
<div class="landing-buttons">
|
||||
<a class="landing-button" target="_blank" href="https://github.com/MoePlayer/APlayer">
|
||||
GitHub
|
||||
</a>
|
||||
|
||||
<a class="landing-button" router-link="/home">
|
||||
Docs
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
h1 {
|
||||
margin: 0;
|
||||
margin-top: -50px;
|
||||
font-weight: normal;
|
||||
font-size: 40px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-top: 20px;
|
||||
color: #999;
|
||||
font-weight: normal;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.landing {
|
||||
padding: 10px;
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
justify-content: center;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.features {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 10px;
|
||||
font-size: 16px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.landing-button {
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 33px;
|
||||
padding: 10px 30px;
|
||||
background-color: white;
|
||||
display: inline-block;
|
||||
margin-right: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.landing-button:hover {
|
||||
border-color: #42b983;
|
||||
color: #42b983;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.aplayer-wrap {
|
||||
width: 600px;
|
||||
max-width: 100%;
|
||||
margin: 20px 0 40px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
search: english
|
||||
---
|
||||
|
||||
# Sponsor APlayer Development
|
||||
|
||||
APlayer is an MIT licensed open source project and completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.
|
||||
|
||||
If you run a business and are using APlayer in a revenue-generating product, it makes business sense to sponsor APlayer development: it ensures the project that your product relies on stays healthy and actively maintained.
|
||||
|
||||
If you are an individual user and have enjoyed the productivity of using APlayer, consider donating as a sign of appreciation - like buying me coffee once in a while :)
|
||||
|
||||
You can support APlayer development via the following methods:
|
||||
|
||||
## One-time Donations
|
||||
|
||||
We accept donations through these channels:
|
||||
|
||||
- [Paypal](https://www.paypal.me/DIYgod)
|
||||
- [WeChat Pay](https://i.imgur.com/aq6PtWa.png)
|
||||
- [Alipay](https://i.imgur.com/wv1Pj2k.png)
|
||||
- Bitcoin: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1
|
||||
|
||||
## Recurring Pledges
|
||||
|
||||
Recurring pledges come with exclusive perks, e.g. having your name or your company logo listed in the APlayer GitHub repository and this website.
|
||||
|
||||
- Become a backer or sponsor via [OpenCollective](https://opencollective.com/aplayer)
|
||||
- E-mail us: i#html.love
|
||||
|
||||
## Current Premium Sponsors
|
||||
|
||||
### Special Sponsors
|
||||
|
||||
<a href="https://pear.hk/" target="_blank">
|
||||
<img width="222px" src="https://i.imgur.com/5qQYmfc.png">
|
||||
</a>
|
||||
<a href="https://console.upyun.com/register/?invite=BkLZ2Xqob" target="_blank">
|
||||
<img width="222px" src="https://imgur.com/apG1uKf.png">
|
||||
</a>
|
||||
|
||||
### OpenCollective backers
|
||||
|
||||

|
||||
|
||||
## APlayer contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
|
||||
<a href="https://github.com/MoePlayer/APlayer/graphs/contributors"><img src="https://opencollective.com/APlayer/contributors.svg?width=890" /></a>
|
||||
@@ -0,0 +1,399 @@
|
||||
---
|
||||
nav: zh-Hans
|
||||
search: zh-Hans
|
||||
---
|
||||
|
||||
# APlayer
|
||||
|
||||
🍭 Wow, such a beautiful HTML5 music player
|
||||
|
||||
## 特别赞助商
|
||||
|
||||
<a href="https://pear.hk/" target="_blank">
|
||||
<img width="222px" src="https://i.imgur.com/5qQYmfc.png">
|
||||
</a>
|
||||
<a href="https://console.upyun.com/register/?invite=BkLZ2Xqob" target="_blank">
|
||||
<img width="222px" src="https://imgur.com/apG1uKf.png">
|
||||
</a>
|
||||
|
||||
## 安装
|
||||
|
||||
使用 npm:
|
||||
|
||||
```
|
||||
npm install aplayer --save
|
||||
```
|
||||
|
||||
使用 Yarn:
|
||||
|
||||
```
|
||||
yarn add aplayer
|
||||
```
|
||||
|
||||
## 入门
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer2"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
<div id="aplayer"></div>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
使用模块管理器:
|
||||
|
||||
```js
|
||||
import 'APlayer/dist/APlayer.min.css';
|
||||
import APlayer from 'APlayer';
|
||||
|
||||
const ap = new APlayer(options);
|
||||
```
|
||||
|
||||
## 参数
|
||||
|
||||
名称 | 默认值 | 描述
|
||||
----|-------|----
|
||||
container | document.querySelector('.aplayer') | 播放器容器元素
|
||||
mini | false | 开启迷你模式, [详情](https://aplayer.js.org/#/home?id=mini-mode)
|
||||
autoplay | false | 音频自动播放
|
||||
theme | '#b7daff' | 主题色
|
||||
loop | 'all' | 音频循环播放, 可选值: 'all', 'one', 'none'
|
||||
order | 'list' | 音频循环顺序, 可选值: 'list', 'random'
|
||||
preload | 'auto' | 预加载,可选值: 'none', 'metadata', 'auto'
|
||||
volume | 0.7 | 默认音量,请注意播放器会记忆用户设置,用户手动设置音量后默认音量即失效
|
||||
audio | - | 音频信息, 应该是一个对象或对象数组
|
||||
audio.name | - | 音频名称
|
||||
audio.artist | - | 音频艺术家
|
||||
audio.url | - | 音频链接
|
||||
audio.cover | - | 音频封面
|
||||
audio.lrc | - | [详情](https://aplayer.js.org/#/home?id=lrc)
|
||||
mutex | true | 互斥,阻止多个播放器同时播放,当前播放器播放时暂停其他播放器
|
||||
lrc | false | [详情](https://aplayer.js.org/#/home?id=lrc)
|
||||
listFolded | false | 列表默认折叠
|
||||
listMaxHeight | - | 列表最大高度
|
||||
|
||||
例如:
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer3"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
theme: '#FADFA3',
|
||||
loop: 'all',
|
||||
order: 'random',
|
||||
preload: 'auto',
|
||||
volume: 0.7,
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg',
|
||||
lrc: 'lrc1.lrc'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg',
|
||||
lrc: 'lrc2.lrc'
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
+ `ap.play()`: 播放音频
|
||||
|
||||
+ `ap.pause()`: 暂停音频
|
||||
|
||||
+ `ap.seek(time: number)`: 跳转到特定时间
|
||||
|
||||
```js
|
||||
ap.seek(100);
|
||||
```
|
||||
|
||||
+ `ap.toggle()`: 切换播放和暂停
|
||||
|
||||
+ `ap.on(event: string, handler: function)`: 绑定音频和播放器事件,[详情](https://aplayer.js.org/#/home?id=event-binding)
|
||||
|
||||
+ `ap.switchAudio(index: number)`: 切换音频列表
|
||||
|
||||
```js
|
||||
ap.switchAudio(1);
|
||||
```
|
||||
|
||||
+ `ap.addAudio(audio)`: 向列表添加新的音频
|
||||
|
||||
```js
|
||||
ap.addAudio([
|
||||
{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
lrc: 'lrc.lrc'
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
+ `ap.removeAudio(index: number)`: 从列表删除音频
|
||||
|
||||
```js
|
||||
ap.removeAudio(1);
|
||||
```
|
||||
|
||||
+ `ap.volume(percentage: number, nostorage: boolean)`: 设置音频音量
|
||||
|
||||
```js
|
||||
ap.volume(0.1, true);
|
||||
```
|
||||
|
||||
+ `ap.destroy()`: 销毁播放器
|
||||
|
||||
+ `ap.audio`: 原生 video
|
||||
|
||||
+ `ap.audio.currentTime`: 返回音频当前播放时间
|
||||
|
||||
+ `ap.audio.duration`: 返回音频总时间
|
||||
|
||||
+ `ap.audio.paused`: 返回音频是否暂停
|
||||
|
||||
+ 支持大多数[原生audio接口](http://www.w3schools.com/tags/ref_av_dom.asp)
|
||||
|
||||
## 事件绑定
|
||||
|
||||
`ap.on(event, handler)`
|
||||
|
||||
```js
|
||||
ap.on('ended', function () {
|
||||
console.log('player ended');
|
||||
});
|
||||
```
|
||||
|
||||
音频事件
|
||||
|
||||
- abort
|
||||
- canplay
|
||||
- canplaythrough
|
||||
- durationchange
|
||||
- emptied
|
||||
- ended
|
||||
- error
|
||||
- loadeddata
|
||||
- loadedmetadata
|
||||
- loadstart
|
||||
- mozaudioavailable
|
||||
- pause
|
||||
- play
|
||||
- playing
|
||||
- progress
|
||||
- ratechange
|
||||
- seeked
|
||||
- seeking
|
||||
- stalled
|
||||
- suspend
|
||||
- timeupdate
|
||||
- volumechange
|
||||
- waiting
|
||||
|
||||
播放器事件
|
||||
|
||||
- switchaudio
|
||||
- addaudio
|
||||
- removeaudio
|
||||
- destroy
|
||||
|
||||
## 歌词
|
||||
|
||||
我们有三种方式来给 APlayer 传递歌词,使用 `lrc` 参数指明使用哪种方式,然后把歌词放到 `audio.lrc` 参数或者 HTML 里。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer4"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
### LRC 文件方式
|
||||
|
||||
第一种方式,把歌词放到 LRC 文件里,音频播放时会加载对应的 LRC 文件。
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 3,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'demo.mp3',
|
||||
cover: 'demo.jpg',
|
||||
lrc: 'lrc.lrc'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### JS 字符串方式
|
||||
|
||||
第二种方式,把歌词放到 JS 字符串里面。
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 1,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'demo.mp3',
|
||||
cover: 'demo.jpg',
|
||||
lrc: '[00:00.00]APlayer\n[00:04.01]is\n[00:08.02]amazing'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### HTML 方式
|
||||
|
||||
第三种方式,把歌词放到 HTML 里面。
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
<div id="player">
|
||||
<pre class="aplayer-lrc-content">
|
||||
[00:00.00]APlayer audio1
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
<!-- ... -->
|
||||
</pre>
|
||||
<pre class="aplayer-lrc-content">
|
||||
[00:00.00]APlayer audio2
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
<!-- ... -->
|
||||
</pre>
|
||||
</div>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 2,
|
||||
audio: [[
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg'
|
||||
}
|
||||
]]
|
||||
});
|
||||
```
|
||||
|
||||
### 歌词格式
|
||||
|
||||
支持下面格式的歌词:
|
||||
|
||||
`[mm:ss]APlayer`
|
||||
|
||||
`[mm:ss.xx]is`
|
||||
|
||||
`[mm:ss.xxx]amazing`
|
||||
|
||||
`[mm:ss.xx][mm:ss.xx]APlayer`
|
||||
|
||||
`[mm:ss.xx]<mm:ss.xx>is`
|
||||
|
||||
`[mm:ss.xx]amazing[mm:ss.xx]APlayer`
|
||||
|
||||
## 播放列表
|
||||
|
||||
当有多个音频时会 APlayer 会展示一个播放列表,`listFolded` 参数指明列表是否默认折叠,`listMaxHeight` 参数指明列表最大高度。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer5"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg',
|
||||
lrc: 'lrc1.lrc'
|
||||
},
|
||||
{
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg',
|
||||
lrc: 'lrc2.lrc'
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
## 迷你模式
|
||||
|
||||
如果你没有足够空间来放置正常模式的播放器,那么你可以考虑使用迷你模式。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer6"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
mini: true,
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
## CDN
|
||||
|
||||
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
|
||||
- [cdnjs](https://cdnjs.com/libraries/aplayer)
|
||||
- [unpkg](https://unpkg.com/aplayer/)
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 为什么播放器不能在手机上自动播放?
|
||||
|
||||
大多数移动端浏览器禁止了音频自动播放。
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
nav: zh-Hans
|
||||
search: zh-Hans
|
||||
---
|
||||
|
||||
# 生态
|
||||
|
||||
让 APlayer 变得更好,请随意在 [`Let me know!`](https://github.com/MoePlayer/APlayer/issues/79) 提交你的项目和产品
|
||||
|
||||
## 帮助
|
||||
|
||||
### 参与讨论
|
||||
|
||||
- [Telegram 群](https://t.me/adplayer)
|
||||
- [QQ 群](https://shang.qq.com/wpa/qunwpa?idkey=bf22213ae0028a82e5adf3f286dfd4f01e0997dc9f1dcd8e831a0a85e799be17): 415835947
|
||||
|
||||
### 提交 issue
|
||||
|
||||
- [MoePlayer/APlayer/issues](https://github.com/MoePlayer/APlayer/issues)
|
||||
|
||||
## 相关项目
|
||||
|
||||
### 插件
|
||||
|
||||
- [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin): Typecho
|
||||
- [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer): Hexo
|
||||
- [Hermit-X(APlayer for WordPress)](https://github.com/liwanglin12/Hermit-X): WordPress
|
||||
- [APlayerHandle](https://github.com/kn007/APlayerHandle): WordPress
|
||||
- [APlayer_for_Z-BlogPHP](https://github.com/fghrsh/APlayer_for_Z-BlogPHP): Z-BlogPHP
|
||||
- [react-aplayer](https://github.com/sabrinaluo/react-aplayer): React
|
||||
- [vue-aplayer](https://github.com/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
### 工具
|
||||
|
||||
- [APlayer-Controler](https://github.com/Mashiro-Sorata/APlayer-Controler): controling tool
|
||||
- [MetingJS](https://github.com/metowolf/MetingJS): work with Meting music API
|
||||
|
||||
## 谁在用 APlayer?
|
||||
|
||||
- [Jelly Rue](http://jellyrue.com/): Jelly Rue, an indie pop-rock band from Tartu.
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [iSearch](http://i.oppsu.cn): 一个提供 iTunes 搜索,试听,高清专辑封面获取,查看最新音乐动态等综合性平台
|
||||
- [LRC歌词编辑器](https://github.com/MoeFE/Lyric): 一款非常实用的在线LRC歌词编辑器
|
||||
- [Аэростатика](https://aerostatica.ru/)
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
nav: zh-Hans
|
||||
search: zh-Hans
|
||||
---
|
||||
|
||||
# 赞助 APlayer 的研发
|
||||
|
||||
APlayer 是采用 MIT 许可的开源项目,使用完全免费。 但是随着项目规模的增长,也需要有相应的资金支持才能持续项目的维护的开发。
|
||||
|
||||
如果你是企业经营者并且将 APlayer 用在商业产品中,那么赞助 APlayer 有商业上的益处:可以让你的产品所依赖的框架保持健康并得到积极的维护。
|
||||
|
||||
如果你是个人开发者并且享受 APlayer 带来的高开发效率,可以用捐助来表示你的谢意 —— 比如偶尔给我买杯咖啡 :)
|
||||
|
||||
你可以通过下列的方法来赞助 APlayer 的开发。
|
||||
|
||||
## 一次性赞助
|
||||
|
||||
我们通过以下方式接受赞助:
|
||||
|
||||
- [微信支付](https://i.imgur.com/aq6PtWa.png)
|
||||
- [支付宝](https://i.imgur.com/wv1Pj2k.png)
|
||||
- [Paypal](https://www.paypal.me/DIYgod)
|
||||
- 比特币: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1
|
||||
|
||||
## 周期性赞助
|
||||
|
||||
周期性赞助可以获得额外的回报,比如你的名字或你的公司 logo 会出现在 APlayer 的 GitHub 仓库和现在我们的官网中。
|
||||
|
||||
- 通过 [OpenCollective](https://opencollective.com/aplayer) 赞助成为 backer 或 sponsor
|
||||
- 给我们发邮件联系赞助事宜: i#html.love
|
||||
|
||||
## 当前的顶级赞助商
|
||||
|
||||
### 特别赞助商
|
||||
|
||||
<a href="https://pear.hk/" target="_blank">
|
||||
<img width="222px" src="https://i.imgur.com/5qQYmfc.png">
|
||||
</a>
|
||||
<a href="https://console.upyun.com/register/?invite=BkLZ2Xqob" target="_blank">
|
||||
<img width="222px" src="https://imgur.com/apG1uKf.png">
|
||||
</a>
|
||||
|
||||
### OpenCollective backers
|
||||
|
||||

|
||||
|
||||
## APlayer 贡献者
|
||||
|
||||
感谢所有贡献者。
|
||||
|
||||
<a href="https://github.com/MoePlayer/APlayer/graphs/contributors"><img src="https://opencollective.com/APlayer/contributors.svg?width=890" /></a>
|
||||
@@ -1,15 +1,21 @@
|
||||
{
|
||||
"name": "aplayer",
|
||||
"version": "1.5.7",
|
||||
"version": "1.7.0",
|
||||
"description": "Wow, such a beautiful html5 music player",
|
||||
"main": "dist/APlayer.min.js",
|
||||
"style": "dist/APlayer.min.css",
|
||||
"scripts": {
|
||||
"test": "webpack",
|
||||
"start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
|
||||
"start": "npm run dev",
|
||||
"build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --colors",
|
||||
"dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack/dev.config.js --watch --colors",
|
||||
"test": "eslint src webpack"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/DIYgod/APlayer.git"
|
||||
"url": "git+https://github.com/DIYgod/APlayer.git",
|
||||
"type": "git"
|
||||
},
|
||||
"keywords": [
|
||||
"player",
|
||||
@@ -17,24 +23,39 @@
|
||||
"html5"
|
||||
],
|
||||
"author": "DIYgod",
|
||||
"license": "SATA",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/DIYgod/APlayer/issues"
|
||||
},
|
||||
"homepage": "https://github.com/DIYgod/APlayer#readme",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^6.4.0",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-preset-es2015": "^6.13.2",
|
||||
"css-loader": "^0.25.0",
|
||||
"exports-loader": "^0.6.3",
|
||||
"file-loader": "^0.9.0",
|
||||
"node-sass": "^3.8.0",
|
||||
"postcss-loader": "^1.0.0",
|
||||
"sass-loader": "^4.0.0",
|
||||
"style-loader": "^0.13.1",
|
||||
"url-loader": "^0.5.7",
|
||||
"webpack": "^1.13.1",
|
||||
"webpack-dev-server": "^1.14.1"
|
||||
"art-template": "4.12.2",
|
||||
"art-template-loader": "1.4.3",
|
||||
"autoprefixer": "^7.2.5",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.2",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"cross-env": "^5.1.3",
|
||||
"css-loader": "^0.28.9",
|
||||
"eslint": "^4.17.0",
|
||||
"eslint-loader": "^1.9.0",
|
||||
"exports-loader": "^0.6.4",
|
||||
"extract-text-webpack-plugin": "^3.0.2",
|
||||
"file-loader": "^1.1.6",
|
||||
"git-revision-webpack-plugin": "^2.5.1",
|
||||
"node-sass": "^4.7.2",
|
||||
"postcss-loader": "^2.1.0",
|
||||
"sass-loader": "^6.0.6",
|
||||
"strip-loader": "^0.1.2",
|
||||
"style-loader": "^0.20.1",
|
||||
"svg-inline-loader": "0.8.0",
|
||||
"template-string-optimize-loader": "^2.2.3",
|
||||
"url-loader": "^0.6.2",
|
||||
"webpack": "^3.10.0",
|
||||
"webpack-dev-server": "^2.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"balloon-css": "^0.5.0",
|
||||
"promise-polyfill": "7.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,844 +0,0 @@
|
||||
console.log("\n %c APlayer 1.5.7 %c http://aplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
|
||||
|
||||
require('./APlayer.scss');
|
||||
|
||||
let instances = [];
|
||||
|
||||
class APlayer {
|
||||
/**
|
||||
* APlayer constructor function
|
||||
*
|
||||
* @param {Object} option - See README
|
||||
* @constructor
|
||||
*/
|
||||
constructor(option) {
|
||||
const svg = {
|
||||
'play': ['0 0 16 31', 'M15.552 15.168q0.448 0.32 0.448 0.832 0 0.448-0.448 0.768l-13.696 8.512q-0.768 0.512-1.312 0.192t-0.544-1.28v-16.448q0-0.96 0.544-1.28t1.312 0.192z'],
|
||||
'pause': ['0 0 17 32', 'M14.080 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048zM2.88 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048z'],
|
||||
'volume-up': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528zM25.152 16q0 2.72-1.536 5.056t-4 3.36q-0.256 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.704 0.672-1.056 1.024-0.512 1.376-0.8 1.312-0.96 2.048-2.4t0.736-3.104-0.736-3.104-2.048-2.4q-0.352-0.288-1.376-0.8-0.672-0.352-0.672-1.056 0-0.448 0.32-0.8t0.8-0.352q0.224 0 0.48 0.096 2.496 1.056 4 3.36t1.536 5.056zM29.728 16q0 4.096-2.272 7.552t-6.048 5.056q-0.224 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.64 0.704-1.056 0.128-0.064 0.384-0.192t0.416-0.192q0.8-0.448 1.44-0.896 2.208-1.632 3.456-4.064t1.216-5.152-1.216-5.152-3.456-4.064q-0.64-0.448-1.44-0.896-0.128-0.096-0.416-0.192t-0.384-0.192q-0.704-0.416-0.704-1.056 0-0.448 0.32-0.8t0.832-0.352q0.224 0 0.448 0.096 3.776 1.632 6.048 5.056t2.272 7.552z'],
|
||||
'volume-down': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528z'],
|
||||
'volume-off': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8z'],
|
||||
'circulation': ['0 0 29 32', 'M25.6 9.92q1.344 0 2.272 0.928t0.928 2.272v9.28q0 1.28-0.928 2.24t-2.272 0.96h-22.4q-1.28 0-2.24-0.96t-0.96-2.24v-9.28q0-1.344 0.96-2.272t2.24-0.928h8v-3.52l6.4 5.76-6.4 5.76v-3.52h-6.72v6.72h19.84v-6.72h-4.8v-4.48h6.080z'],
|
||||
'random': ['0 0 33 31', 'M29.867 9.356l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.219-0.5-0.5v-3.002h-4.002c-2.079 0-3.064 1.423-3.94 3.111-0.453 0.875-0.844 1.782-1.219 2.673-1.735 4.033-3.768 8.223-8.849 8.223h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.079 0 3.064-1.423 3.94-3.111 0.453-0.875 0.844-1.782 1.219-2.673 1.735-4.033 3.768-8.223 8.849-8.223h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36zM10.262 14.781c-0.907-1.892-1.907-3.783-4.268-3.783h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.783 0 4.831 1.298 6.41 3.518-0.876 1.344-1.517 2.798-2.142 4.268zM29.867 23.363l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.235-0.5-0.5v-3.002c-4.643 0-7.504 0.547-10.396-3.518 0.86-1.344 1.501-2.798 2.126-4.268 0.907 1.892 1.907 3.783 4.268 3.783h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36z'],
|
||||
'order': ['0 0 32 32', 'M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z'],
|
||||
'single': ['0 0 38 32', 'M2.072 21.577c0.71-0.197 1.125-0.932 0.928-1.641-0.221-0.796-0.333-1.622-0.333-2.457 0-5.049 4.108-9.158 9.158-9.158h5.428c0.056-0.922 0.221-1.816 0.482-2.667h-5.911c-3.158 0-6.128 1.23-8.361 3.463s-3.463 5.203-3.463 8.361c0 1.076 0.145 2.143 0.431 3.171 0.164 0.59 0.7 0.976 1.284 0.976 0.117 0 0.238-0.016 0.357-0.049zM21.394 25.613h-12.409v-2.362c0-0.758-0.528-1.052-1.172-0.652l-5.685 3.522c-0.644 0.4-0.651 1.063-0.014 1.474l5.712 3.69c0.637 0.411 1.158 0.127 1.158-0.63v-2.374h12.409c3.158 0 6.128-1.23 8.361-3.463 1.424-1.424 2.44-3.148 2.99-5.029-0.985 0.368-2.033 0.606-3.125 0.691-1.492 3.038-4.619 5.135-8.226 5.135zM28.718 0c-4.985 0-9.026 4.041-9.026 9.026s4.041 9.026 9.026 9.026 9.026-4.041 9.026-9.026-4.041-9.026-9.026-9.026zM30.392 13.827h-1.728v-6.822c-0.635 0.576-1.433 1.004-2.407 1.285v-1.713c0.473-0.118 0.975-0.325 1.506-0.62 0.532-0.325 0.975-0.665 1.329-1.034h1.3v8.904z'],
|
||||
'menu': ['0 0 22 32', 'M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z']
|
||||
};
|
||||
this.getSVG = (type) => {
|
||||
return `
|
||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" height="100%" version="1.1" viewBox="${svg[type][0]}" width="100%">
|
||||
<use xlink:href="#aplayer-${type}"></use>
|
||||
<path class="aplayer-fill" d="${svg[type][1]}" id="aplayer-${type}"></path>
|
||||
</svg>
|
||||
`;
|
||||
};
|
||||
|
||||
this.isMobile = /mobile/i.test(window.navigator.userAgent);
|
||||
// compatibility: some mobile browsers don't suppose autoplay
|
||||
if (this.isMobile) {
|
||||
option.autoplay = false;
|
||||
}
|
||||
|
||||
// default options
|
||||
const defaultOption = {
|
||||
element: document.getElementsByClassName('aplayer')[0],
|
||||
narrow: false,
|
||||
autoplay: false,
|
||||
mutex: true,
|
||||
showlrc: 0,
|
||||
theme: '#b7daff',
|
||||
mode: 'circulation'
|
||||
};
|
||||
for (let defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
|
||||
option[defaultKey] = defaultOption[defaultKey];
|
||||
}
|
||||
}
|
||||
|
||||
// multiple music
|
||||
this.playIndex = Object.prototype.toString.call(option.music) === '[object Array]' ? 0 : -1;
|
||||
|
||||
this.option = option;
|
||||
this.audios = [];
|
||||
this.mode = option.mode;
|
||||
|
||||
/**
|
||||
* Parse second to 00:00 format. 00:00:00 if audio is over an hour long.
|
||||
*
|
||||
* @param {Number} second
|
||||
* @return {String} 00:00 format. 00:00:00 if over an hour long.
|
||||
*/
|
||||
this.secondToTime = (second) => {
|
||||
const add0 = (num) => {
|
||||
return num < 10 ? '0' + num : '' + num;
|
||||
};
|
||||
const min = parseInt(second / 60);
|
||||
const sec = parseInt(second - min * 60);
|
||||
const hours = parseInt(min / 60);
|
||||
const minAdjust = parseInt((second / 60) - (60 * parseInt((second / 60) / 60)));
|
||||
return second >= 3600 ? add0(hours) + ':' + add0(minAdjust) + ':' + add0(sec) : add0(min) + ':' + add0(sec);
|
||||
};
|
||||
|
||||
// save lrc
|
||||
this.element = this.option.element;
|
||||
if (this.option.showlrc === 2 || this.option.showlrc === true) {
|
||||
this.savelrc = [];
|
||||
for (let i = 0; i < this.element.getElementsByClassName('aplayer-lrc-content').length; i++) {
|
||||
this.savelrc.push(this.element.getElementsByClassName('aplayer-lrc-content')[i].innerHTML);
|
||||
}
|
||||
}
|
||||
this.lrcs = [];
|
||||
|
||||
/**
|
||||
* Update progress bar, including loading progress bar and play progress bar
|
||||
*
|
||||
* @param {String} type - Point out which bar it is, should be played loaded or volume
|
||||
* @param {Number} percentage
|
||||
* @param {String} direction - Point out the direction of this bar, Should be height or width
|
||||
*/
|
||||
this.updateBar = (type, percentage, direction) => {
|
||||
percentage = percentage > 0 ? percentage : 0;
|
||||
percentage = percentage < 1 ? percentage : 1;
|
||||
bar[type + 'Bar'].style[direction] = percentage * 100 + '%';
|
||||
};
|
||||
|
||||
/**
|
||||
* Update lrc
|
||||
*
|
||||
* @param {Number} currentTime
|
||||
*/
|
||||
this.updateLrc = (currentTime = this.audio.currentTime) => {
|
||||
if (this.lrcIndex > this.lrc.length - 1 || currentTime < this.lrc[this.lrcIndex][0] || (!this.lrc[this.lrcIndex + 1] || currentTime >= this.lrc[this.lrcIndex + 1][0])) {
|
||||
for (let i = 0; i < this.lrc.length; i++) {
|
||||
if (currentTime >= this.lrc[i][0] && (!this.lrc[i + 1] || currentTime < this.lrc[i + 1][0])) {
|
||||
this.lrcIndex = i;
|
||||
this.lrcContents.style.transform = `translateY(${-this.lrcIndex * 16}px)`;
|
||||
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 16}px)`;
|
||||
this.lrcContents.getElementsByClassName('aplayer-lrc-current')[0].classList.remove('aplayer-lrc-current');
|
||||
this.lrcContents.getElementsByTagName('p')[i].classList.add('aplayer-lrc-current');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// define APlayer events
|
||||
const eventTypes = ['play', 'pause', 'canplay', 'playing', 'ended', 'error'];
|
||||
this.event = {};
|
||||
for (let i = 0; i < eventTypes.length; i++) {
|
||||
this.event[eventTypes[i]] = [];
|
||||
}
|
||||
this.trigger = (type) => {
|
||||
for (let i = 0; i < this.event[type].length; i++) {
|
||||
this.event[type][i]();
|
||||
}
|
||||
};
|
||||
|
||||
this.multiple = this.playIndex > -1;
|
||||
this.music = this.multiple ? this.option.music[this.playIndex] : this.option.music;
|
||||
|
||||
// add class aplayer-withlrc
|
||||
if (this.option.showlrc) {
|
||||
this.element.classList.add('aplayer-withlrc');
|
||||
}
|
||||
if (this.option.music.length > 1) {
|
||||
this.element.classList.add('aplayer-list');
|
||||
}
|
||||
|
||||
if (!this.multiple && this.mode !== 'circulation' && this.mode !== 'order') {
|
||||
this.mode = 'circulation';
|
||||
}
|
||||
this.getRandomOrder();
|
||||
|
||||
// fill in HTML
|
||||
let eleHTML = `
|
||||
<div class="aplayer-pic" ${(this.music.pic ? (`style="background-image: url('${this.music.pic}');"`) : ``)}>
|
||||
<div class="aplayer-button aplayer-play">
|
||||
<button class="aplayer-icon aplayer-icon-play">`
|
||||
+ this.getSVG('play')
|
||||
+ ` </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-info">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title"></span>
|
||||
<span class="aplayer-author"></span>
|
||||
</div>
|
||||
<div class="aplayer-lrc">
|
||||
<div class="aplayer-lrc-contents" style="transform: translateY(0); -webkit-transform: translateY(0);"></div>
|
||||
</div>
|
||||
<div class="aplayer-controller">
|
||||
<div class="aplayer-bar-wrap">
|
||||
<div class="aplayer-bar">
|
||||
<div class="aplayer-loaded" style="width: 0"></div>
|
||||
<div class="aplayer-played" style="width: 0; background: ${this.option.theme};">
|
||||
<span class="aplayer-thumb" style="border: 1px solid ${this.option.theme};"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-time">
|
||||
<span class="aplayer-time-inner">
|
||||
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||
</span>
|
||||
<div class="aplayer-volume-wrap">
|
||||
<button class="aplayer-icon aplayer-icon-volume-down" ${this.isMobile ? 'style="display: none;"' : ''}>`
|
||||
+ this.getSVG('volume-down')
|
||||
+ ` </button>
|
||||
<div class="aplayer-volume-bar-wrap">
|
||||
<div class="aplayer-volume-bar">
|
||||
<div class="aplayer-volume" style="height: 80%; background: ${this.option.theme};"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="aplayer-icon aplayer-icon-mode">`
|
||||
+ this.getSVG(this.mode)
|
||||
+ ` </button>
|
||||
${(this.multiple ? `<button class="aplayer-icon aplayer-icon-menu">`
|
||||
+ this.getSVG('menu')
|
||||
+ ` </button>` : ``)}
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
if (this.multiple) {
|
||||
eleHTML += `
|
||||
<div class="aplayer-list" ${this.option.listmaxheight ? `style="max-height: ${this.option.listmaxheight}` : ``}">
|
||||
<ol>`;
|
||||
for (let i = 0; i < this.option.music.length; i++) {
|
||||
eleHTML += `
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: ${this.option.theme};"></span>
|
||||
<span class="aplayer-list-index">${(i + 1)}</span>
|
||||
<span class="aplayer-list-title">${this.option.music[i].title}</span>
|
||||
<span class="aplayer-list-author">${this.option.music[i].author}</span>
|
||||
</li>`
|
||||
}
|
||||
eleHTML += `
|
||||
</ol>
|
||||
</div>`
|
||||
}
|
||||
this.element.innerHTML = eleHTML;
|
||||
|
||||
// hide mode button in arrow container
|
||||
if (this.element.offsetWidth < 300) {
|
||||
this.element.getElementsByClassName('aplayer-icon-mode')[0].style.display = 'none';
|
||||
}
|
||||
|
||||
this.ptime = this.element.getElementsByClassName('aplayer-ptime')[0];
|
||||
|
||||
if (this.element.getElementsByClassName('aplayer-info')[0].offsetWidth < 200) {
|
||||
this.element.getElementsByClassName('aplayer-time')[0].classList.add('aplayer-time-narrow');
|
||||
}
|
||||
// fix the width of aplayer bar
|
||||
let bar = {};
|
||||
bar.barWrap = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
|
||||
|
||||
// switch to narrow style
|
||||
if (this.option.narrow) {
|
||||
this.element.classList.add('aplayer-narrow');
|
||||
}
|
||||
|
||||
// play and pause button
|
||||
this.button = this.element.getElementsByClassName('aplayer-button')[0];
|
||||
this.button.addEventListener('click', (e) => {
|
||||
this.toggle();
|
||||
});
|
||||
|
||||
// click music list: change music
|
||||
if (this.multiple) {
|
||||
const listItem = this.element.getElementsByClassName('aplayer-list')[0].getElementsByTagName('li');
|
||||
for (let i = 0; i < this.option.music.length; i++) {
|
||||
listItem[i].addEventListener('click', () => {
|
||||
const musicIndex = parseInt(listItem[i].getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
||||
if (musicIndex !== this.playIndex) {
|
||||
this.setMusic(musicIndex);
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// control play progress
|
||||
bar.playedBar = this.element.getElementsByClassName('aplayer-played')[0];
|
||||
bar.loadedBar = this.element.getElementsByClassName('aplayer-loaded')[0];
|
||||
const thumb = this.element.getElementsByClassName('aplayer-thumb')[0];
|
||||
let barWidth;
|
||||
bar.barWrap.addEventListener('click', (event) => {
|
||||
const e = event || window.event;
|
||||
barWidth = bar.barWrap.clientWidth;
|
||||
const percentage = (e.clientX - getElementViewLeft(bar.barWrap)) / barWidth;
|
||||
this.updateBar('played', percentage, 'width');
|
||||
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(percentage * this.audio.duration);
|
||||
this.audio.currentTime = parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration;
|
||||
});
|
||||
|
||||
thumb.addEventListener('mouseover', () => {
|
||||
thumb.style.background = this.option.theme;
|
||||
});
|
||||
thumb.addEventListener('mouseout', () => {
|
||||
thumb.style.background = '#fff';
|
||||
});
|
||||
|
||||
const thumbMove = (event) => {
|
||||
const e = event || window.event;
|
||||
let percentage = (e.clientX - getElementViewLeft(bar.barWrap)) / barWidth;
|
||||
percentage = percentage > 0 ? percentage : 0;
|
||||
percentage = percentage < 1 ? percentage : 1;
|
||||
this.updateBar('played', percentage, 'width');
|
||||
if (this.option.showlrc) {
|
||||
this.updateLrc(parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration);
|
||||
}
|
||||
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(percentage * this.audio.duration);
|
||||
};
|
||||
|
||||
const thumbUp = () => {
|
||||
document.removeEventListener('mouseup', thumbUp);
|
||||
document.removeEventListener('mousemove', thumbMove);
|
||||
this.audio.currentTime = parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration;
|
||||
this.playedTime = setInterval(() => {
|
||||
this.updateBar('played', this.audio.currentTime / this.audio.duration, 'width');
|
||||
if (this.option.showlrc) {
|
||||
this.updateLrc();
|
||||
}
|
||||
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(this.audio.currentTime);
|
||||
this.trigger('playing');
|
||||
}, 100);
|
||||
};
|
||||
|
||||
thumb.addEventListener('mousedown', () => {
|
||||
barWidth = bar.barWrap.clientWidth;
|
||||
clearInterval(this.playedTime);
|
||||
document.addEventListener('mousemove', thumbMove);
|
||||
document.addEventListener('mouseup', thumbUp);
|
||||
});
|
||||
|
||||
// control volume
|
||||
bar.volumeBar = this.element.getElementsByClassName('aplayer-volume')[0];
|
||||
const volumeBarWrap = this.element.getElementsByClassName('aplayer-volume-bar')[0];
|
||||
this.volumeicon = this.element.getElementsByClassName('aplayer-time')[0].getElementsByTagName('button')[0];
|
||||
const barHeight = 35;
|
||||
this.element.getElementsByClassName('aplayer-volume-bar-wrap')[0].addEventListener('click', (event) => {
|
||||
const e = event || window.event;
|
||||
let percentage = (barHeight - e.clientY + getElementViewTop(volumeBarWrap)) / barHeight;
|
||||
percentage = percentage > 0 ? percentage : 0;
|
||||
percentage = percentage < 1 ? percentage : 1;
|
||||
this.volume(percentage);
|
||||
});
|
||||
this.volumeicon.addEventListener('click', () => {
|
||||
if (this.audio.muted) {
|
||||
this.audio.muted = false;
|
||||
this.volumeicon.className = this.audio.volume === 1 ? 'aplayer-icon aplayer-icon-volume-up' : 'aplayer-icon aplayer-icon-volume-down';
|
||||
if (this.audio.volume === 1) {
|
||||
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-up';
|
||||
this.volumeicon.innerHTML = this.getSVG('volume-up');
|
||||
}
|
||||
else {
|
||||
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-down';
|
||||
this.volumeicon.innerHTML = this.getSVG('volume-down');
|
||||
}
|
||||
this.updateBar('volume', this.audio.volume, 'height');
|
||||
}
|
||||
else {
|
||||
this.audio.muted = true;
|
||||
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-off';
|
||||
this.volumeicon.innerHTML = this.getSVG('volume-off');
|
||||
this.updateBar('volume', 0, 'height');
|
||||
}
|
||||
});
|
||||
|
||||
// get element's view position
|
||||
function getElementViewLeft(element) {
|
||||
let actualLeft = element.offsetLeft;
|
||||
let current = element.offsetParent;
|
||||
let elementScrollLeft;
|
||||
while (current !== null) {
|
||||
actualLeft += current.offsetLeft;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
elementScrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
return actualLeft - elementScrollLeft;
|
||||
}
|
||||
|
||||
function getElementViewTop(element) {
|
||||
let actualTop = element.offsetTop;
|
||||
let current = element.offsetParent;
|
||||
let elementScrollTop;
|
||||
while (current !== null) {
|
||||
actualTop += current.offsetTop;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
elementScrollTop = document.body.scrollTop + document.documentElement.scrollTop;
|
||||
return actualTop - elementScrollTop;
|
||||
}
|
||||
|
||||
// mode control
|
||||
const modeEle = this.element.getElementsByClassName('aplayer-icon-mode')[0];
|
||||
modeEle.addEventListener('click', () => {
|
||||
if (this.multiple) {
|
||||
if (this.mode === 'random') {
|
||||
this.mode = 'single';
|
||||
}
|
||||
else if (this.mode === 'single') {
|
||||
this.mode = 'order';
|
||||
}
|
||||
else if (this.mode === 'order') {
|
||||
this.mode = 'circulation';
|
||||
}
|
||||
else if (this.mode === 'circulation') {
|
||||
this.mode = 'random';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.mode === 'circulation') {
|
||||
this.mode = 'order';
|
||||
}
|
||||
else {
|
||||
this.mode = 'circulation';
|
||||
}
|
||||
}
|
||||
modeEle.innerHTML = this.getSVG(this.mode);
|
||||
this.audio.loop = !(this.multiple || this.mode === 'order');
|
||||
});
|
||||
|
||||
// toggle menu control
|
||||
if (this.multiple) {
|
||||
const list = this.element.getElementsByClassName('aplayer-list')[0];
|
||||
list.style.height = list.offsetHeight + 'px';
|
||||
this.element.getElementsByClassName('aplayer-icon-menu')[0].addEventListener('click', () => {
|
||||
if (!list.classList.contains('aplayer-list-hide')) {
|
||||
list.classList.add('aplayer-list-hide');
|
||||
}
|
||||
else {
|
||||
list.classList.remove('aplayer-list-hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.mode === 'random') {
|
||||
this.setMusic(this.randomOrder[0]);
|
||||
}
|
||||
else {
|
||||
this.setMusic(0);
|
||||
}
|
||||
|
||||
instances.push(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set music
|
||||
*/
|
||||
setMusic(index) {
|
||||
// get this.music
|
||||
if (this.multiple && typeof(index) !== 'undefined') {
|
||||
this.playIndex = index;
|
||||
}
|
||||
const indexMusic = this.playIndex;
|
||||
this.music = this.multiple ? this.option.music[indexMusic] : this.option.music;
|
||||
|
||||
// set html
|
||||
if (this.music.pic) {
|
||||
this.element.getElementsByClassName('aplayer-pic')[0].style.backgroundImage = `url('${this.music.pic}')`;
|
||||
}
|
||||
this.element.getElementsByClassName('aplayer-title')[0].innerHTML = this.music.title;
|
||||
this.element.getElementsByClassName('aplayer-author')[0].innerHTML = ` - ${this.music.author}`;
|
||||
if (this.multiple) {
|
||||
if (this.element.getElementsByClassName('aplayer-list-light')[0]) {
|
||||
this.element.getElementsByClassName('aplayer-list-light')[0].classList.remove('aplayer-list-light');
|
||||
}
|
||||
this.element.getElementsByClassName('aplayer-list')[0].getElementsByTagName('li')[indexMusic].classList.add('aplayer-list-light');
|
||||
}
|
||||
|
||||
// set the previous audio object
|
||||
if (this.audio) {
|
||||
this.pause();
|
||||
this.audio.currentTime = 0;
|
||||
}
|
||||
|
||||
if (this.multiple) {
|
||||
this.element.getElementsByClassName('aplayer-list')[0].scrollTop = indexMusic * 33;
|
||||
}
|
||||
|
||||
// get this audio object
|
||||
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
|
||||
this.audio = document.createElement("audio");
|
||||
this.audio.src = this.music.url;
|
||||
this.audio.preload = this.option.preload ? this.option.preload : 'auto';
|
||||
|
||||
this.audio.addEventListener('play', () => {
|
||||
this.play();
|
||||
});
|
||||
|
||||
this.audio.addEventListener('pause', () => {
|
||||
this.pause();
|
||||
});
|
||||
|
||||
// show audio time: the metadata has loaded or changed
|
||||
this.audio.addEventListener('durationchange', () => {
|
||||
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.element.getElementsByClassName('aplayer-dtime')[0].innerHTML = this.secondToTime(this.audio.duration);
|
||||
}
|
||||
});
|
||||
|
||||
// show audio loaded bar: to inform interested parties of progress downloading the media
|
||||
this.audio.addEventListener('progress', () => {
|
||||
const percentage = this.audio.buffered.length ? this.audio.buffered.end(this.audio.buffered.length - 1) / this.audio.duration : 0;
|
||||
this.updateBar('loaded', percentage, 'width');
|
||||
});
|
||||
|
||||
// audio download error: an error occurs
|
||||
this.audio.addEventListener('error', () => {
|
||||
this.element.getElementsByClassName('aplayer-author')[0].innerHTML = ` - Error happens ╥﹏╥`;
|
||||
this.trigger('pause');
|
||||
});
|
||||
|
||||
// audio can play: enough data is available that the media can be played
|
||||
this.audio.addEventListener('canplay', () => {
|
||||
this.trigger('canplay');
|
||||
});
|
||||
|
||||
// multiple music play
|
||||
this.ended = false;
|
||||
if (this.multiple) {
|
||||
this.audio.addEventListener('ended', () => {
|
||||
if (this.isMobile) {
|
||||
this.ended = true;
|
||||
this.pause();
|
||||
return;
|
||||
}
|
||||
if (this.audio.currentTime !== 0) {
|
||||
if (this.mode === 'random') {
|
||||
this.setMusic(this.nextRandomNum());
|
||||
}
|
||||
else if (this.mode === 'single') {
|
||||
this.setMusic(this.playIndex);
|
||||
}
|
||||
else if (this.mode === 'order') {
|
||||
if (this.playIndex < this.option.music.length - 1) {
|
||||
this.setMusic(++this.playIndex);
|
||||
}
|
||||
else {
|
||||
this.ended = true;
|
||||
this.pause();
|
||||
this.trigger('ended');
|
||||
}
|
||||
}
|
||||
else if (this.mode === 'circulation') {
|
||||
if (this.playIndex < this.option.music.length - 1) {
|
||||
this.setMusic(++this.playIndex);
|
||||
}
|
||||
else {
|
||||
this.setMusic(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.audio.addEventListener('ended', () => {
|
||||
if (this.mode === 'order') {
|
||||
this.ended = true;
|
||||
this.pause();
|
||||
this.trigger('ended');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// control volume
|
||||
this.audio.volume = parseInt(this.element.getElementsByClassName('aplayer-volume')[0].style.height) / 100;
|
||||
|
||||
// loop
|
||||
this.audio.loop = !(this.multiple || this.mode === 'order');
|
||||
|
||||
if (this.multiple) {
|
||||
this.audios[indexMusic] = this.audio;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.audio = this.audios[indexMusic];
|
||||
this.audio.volume = parseInt(this.element.getElementsByClassName('aplayer-volume')[0].style.height) / 100;
|
||||
this.audio.currentTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse lrc, suppose multiple time tag
|
||||
*
|
||||
* @param {String} lrc_s - Format:
|
||||
* [mm:ss.xx]lyric
|
||||
* [mm:ss.xxx]lyric
|
||||
* [mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
|
||||
*
|
||||
* @return {String} [[time, text], [time, text], [time, text], ...]
|
||||
*/
|
||||
const parseLrc = (lrc_s) => {
|
||||
const lyric = lrc_s.split('\n');
|
||||
let lrc = [];
|
||||
const lyricLen = lyric.length;
|
||||
for (let i = 0; i < lyricLen; i++) {
|
||||
// match lrc time
|
||||
const lrcTimes = lyric[i].match(/\[(\d{2}):(\d{2})\.(\d{2,3})]/g);
|
||||
// match lrc text
|
||||
const lrcText = lyric[i].replace(/\[(\d{2}):(\d{2})\.(\d{2,3})]/g, '').replace(/^\s+|\s+$/g, '');
|
||||
|
||||
if (lrcTimes != null) {
|
||||
// handle multiple time tag
|
||||
const timeLen = lrcTimes.length;
|
||||
for (let j = 0; j < timeLen; j++) {
|
||||
const oneTime = /\[(\d{2}):(\d{2})\.(\d{2,3})]/.exec(lrcTimes[j]);
|
||||
const lrcTime = (oneTime[1]) * 60 + parseInt(oneTime[2]) + parseInt(oneTime[3]) / ((oneTime[3] + '').length === 2 ? 100 : 1000);
|
||||
lrc.push([lrcTime, lrcText]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// sort by time
|
||||
lrc.sort((a, b) => a[0] - b[0]);
|
||||
return lrc;
|
||||
};
|
||||
|
||||
// fill in lrc
|
||||
if (this.option.showlrc) {
|
||||
const index = this.multiple ? indexMusic : 0;
|
||||
|
||||
if (!this.lrcs[index]) {
|
||||
let lrcs = '';
|
||||
if (this.option.showlrc === 1) {
|
||||
if (this.multiple) {
|
||||
lrcs = this.option.music[index].lrc;
|
||||
}
|
||||
else {
|
||||
lrcs = this.option.music.lrc;
|
||||
}
|
||||
}
|
||||
else if (this.option.showlrc === 2 || this.option.showlrc === true) {
|
||||
lrcs = this.savelrc[index];
|
||||
}
|
||||
else if (this.option.showlrc === 3) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
|
||||
lrcs = xhr.responseText;
|
||||
this.lrcs[index] = parseLrc(lrcs);
|
||||
this.lrc = this.lrcs[index];
|
||||
let lrcHTML = '';
|
||||
this.lrcContents = this.element.getElementsByClassName('aplayer-lrc-contents')[0];
|
||||
for (let i = 0; i < this.lrc.length; i++) {
|
||||
lrcHTML += `<p>${this.lrc[i][1]}</p>`;
|
||||
}
|
||||
this.lrcContents.innerHTML = lrcHTML;
|
||||
if (!this.lrcIndex) {
|
||||
this.lrcIndex = 0;
|
||||
}
|
||||
this.lrcContents.getElementsByTagName('p')[0].classList.add('aplayer-lrc-current');
|
||||
this.lrcContents.style.transform = 'translateY(0px)';
|
||||
this.lrcContents.style.webkitTransform = 'translateY(0px)';
|
||||
}
|
||||
else {
|
||||
console.log('Request was unsuccessful: ' + xhr.status);
|
||||
}
|
||||
}
|
||||
};
|
||||
let apiurl;
|
||||
if (this.multiple) {
|
||||
apiurl = this.option.music[index].lrc;
|
||||
}
|
||||
else {
|
||||
apiurl = this.option.music.lrc;
|
||||
}
|
||||
xhr.open('get', apiurl, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
if (lrcs) {
|
||||
this.lrcs[index] = parseLrc(lrcs);
|
||||
}
|
||||
else {
|
||||
this.lrcs[index] = [['00:00', 'Loading']];
|
||||
}
|
||||
}
|
||||
|
||||
this.lrc = this.lrcs[index];
|
||||
let lrcHTML = '';
|
||||
this.lrcContents = this.element.getElementsByClassName('aplayer-lrc-contents')[0];
|
||||
for (let i = 0; i < this.lrc.length; i++) {
|
||||
lrcHTML += `<p>${this.lrc[i][1]}</p>`;
|
||||
}
|
||||
this.lrcContents.innerHTML = lrcHTML;
|
||||
if (!this.lrcIndex) {
|
||||
this.lrcIndex = 0;
|
||||
}
|
||||
this.lrcContents.getElementsByTagName('p')[0].classList.add('aplayer-lrc-current');
|
||||
this.lrcContents.style.transform = 'translateY(0px)';
|
||||
this.lrcContents.style.webkitTransform = 'translateY(0px)';
|
||||
}
|
||||
|
||||
// set duration time
|
||||
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.element.getElementsByClassName('aplayer-dtime')[0].innerHTML = this.audio.duration ? this.secondToTime(this.audio.duration) : '00:00';
|
||||
}
|
||||
|
||||
// autoplay
|
||||
if (this.option.autoplay && !this.isMobile) {
|
||||
this.play();
|
||||
}
|
||||
this.option.autoplay = true; // autoplay next music
|
||||
|
||||
if (this.isMobile) {
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play music
|
||||
*/
|
||||
play(time) {
|
||||
if (Object.prototype.toString.call(time) === '[object Number]') {
|
||||
this.audio.currentTime = time;
|
||||
}
|
||||
if (this.button.classList.contains('aplayer-play')) {
|
||||
this.button.classList.remove('aplayer-play');
|
||||
this.button.classList.add('aplayer-pause');
|
||||
this.button.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
this.button.innerHTML = `
|
||||
<button class="aplayer-icon aplayer-icon-pause">`
|
||||
+ this.getSVG('pause')
|
||||
+ ` </button>`;
|
||||
}, 100);
|
||||
|
||||
// pause other players (Thanks @Aprikyblue)
|
||||
if (this.option.mutex) {
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
if (this != instances[i]) {
|
||||
instances[i].pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.audio.play();
|
||||
if (this.playedTime) {
|
||||
clearInterval(this.playedTime);
|
||||
}
|
||||
this.playedTime = setInterval(() => {
|
||||
this.updateBar('played', this.audio.currentTime / this.audio.duration, 'width');
|
||||
if (this.option.showlrc) {
|
||||
this.updateLrc();
|
||||
}
|
||||
this.ptime.innerHTML = this.secondToTime(this.audio.currentTime);
|
||||
this.trigger('playing');
|
||||
}, 100);
|
||||
this.trigger('play');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause music
|
||||
*/
|
||||
pause() {
|
||||
if (this.button.classList.contains('aplayer-pause') || this.ended) {
|
||||
this.ended = false;
|
||||
this.button.classList.remove('aplayer-pause');
|
||||
this.button.classList.add('aplayer-play');
|
||||
this.button.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
this.button.innerHTML = `
|
||||
<button class="aplayer-icon aplayer-icon-play">`
|
||||
+ this.getSVG('play')
|
||||
+ ` </button>`;
|
||||
}, 100);
|
||||
this.audio.pause();
|
||||
clearInterval(this.playedTime);
|
||||
this.trigger('pause');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set volume
|
||||
*/
|
||||
volume(percentage) {
|
||||
this.updateBar('volume', percentage, 'height');
|
||||
this.audio.volume = percentage;
|
||||
if (this.audio.muted) {
|
||||
this.audio.muted = false;
|
||||
}
|
||||
if (percentage === 1) {
|
||||
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-up';
|
||||
this.volumeicon.innerHTML = this.getSVG('volume-up');
|
||||
}
|
||||
else {
|
||||
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-down';
|
||||
this.volumeicon.innerHTML = this.getSVG('volume-down');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* attach event
|
||||
*/
|
||||
on(name, func) {
|
||||
if (typeof func === 'function') {
|
||||
this.event[name].push(func);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle between play and pause
|
||||
*/
|
||||
toggle() {
|
||||
if (this.button.classList.contains('aplayer-play')) {
|
||||
this.play();
|
||||
}
|
||||
else if (this.button.classList.contains('aplayer-pause')) {
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get random order, using Fisher–Yates shuffle
|
||||
*/
|
||||
getRandomOrder() {
|
||||
function random(min, max) {
|
||||
if (max == null) {
|
||||
max = min;
|
||||
min = 0;
|
||||
}
|
||||
return min + Math.floor(Math.random() * (max - min + 1));
|
||||
}
|
||||
function shuffle(arr) {
|
||||
var length = arr.length,
|
||||
shuffled = new Array(length);
|
||||
for (var index = 0, rand; index < length; index++) {
|
||||
rand = random(0, index);
|
||||
if (rand !== index) shuffled[index] = shuffled[rand];
|
||||
shuffled[rand] = arr[index];
|
||||
}
|
||||
return shuffled;
|
||||
}
|
||||
if (this.multiple) {
|
||||
if (!this.normalOrder) {
|
||||
this.normalOrder = [];
|
||||
for (let i = 0; i < this.option.music.length; i++) {
|
||||
this.normalOrder[i] = i;
|
||||
}
|
||||
}
|
||||
this.randomOrder = shuffle(this.normalOrder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get next random number
|
||||
*/
|
||||
nextRandomNum() {
|
||||
if (this.multiple) {
|
||||
let index = this.randomOrder.indexOf(this.playIndex);
|
||||
if (index === this.randomOrder.length - 1) {
|
||||
return this.randomOrder[0];
|
||||
}
|
||||
else {
|
||||
return this.randomOrder[index + 1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = APlayer;
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M4 16c0-6.6 5.4-12 12-12s12 5.4 12 12c0 1.2-0.8 2-2 2s-2-0.8-2-2c0-4.4-3.6-8-8-8s-8 3.6-8 8 3.6 8 8 8c1.2 0 2 0.8 2 2s-0.8 2-2 2c-6.6 0-12-5.4-12-12z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 253 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 29 32">
|
||||
<path d="M9.333 9.333h13.333v4l5.333-5.333-5.333-5.333v4h-16v8h2.667v-5.333zM22.667 22.667h-13.333v-4l-5.333 5.333 5.333 5.333v-4h16v-8h-2.667v5.333z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 244 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 29 32">
|
||||
<path d="M2.667 7.027l1.707-1.693 22.293 22.293-1.693 1.707-4-4h-11.64v4l-5.333-5.333 5.333-5.333v4h8.973l-8.973-8.973v0.973h-2.667v-3.64l-4-4zM22.667 17.333h2.667v5.573l-2.667-2.667v-2.907zM22.667 6.667v-4l5.333 5.333-5.333 5.333v-4h-10.907l-2.667-2.667h13.573z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 357 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 33 32">
|
||||
<path d="M9.333 9.333h13.333v4l5.333-5.333-5.333-5.333v4h-16v8h2.667v-5.333zM22.667 22.667h-13.333v-4l-5.333 5.333 5.333 5.333v-4h16v-8h-2.667v5.333zM17.333 20v-8h-1.333l-2.667 1.333v1.333h2v5.333h2z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 294 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 22 32">
|
||||
<path d="M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 472 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 174 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M22.667 4l7 6-7 6 7 6-7 6v-4h-3.653l-3.76-3.76 2.827-2.827 2.587 2.587h2v-8h-2l-12 12h-6v-4h4.347l12-12h3.653v-4zM2.667 8h6l3.76 3.76-2.827 2.827-2.587-2.587h-4.347v-4z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 272 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 17 32">
|
||||
<path d="M14.080 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048zM2.88 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 288 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 16 31">
|
||||
<path d="M15.552 15.168q0.448 0.32 0.448 0.832 0 0.448-0.448 0.768l-13.696 8.512q-0.768 0.512-1.312 0.192t-0.544-1.28v-16.448q0-0.96 0.544-1.28t1.312 0.192z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 251 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32">
|
||||
<path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 604 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32">
|
||||
<path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 301 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 28 32">
|
||||
<path d="M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528zM25.152 16q0 2.72-1.536 5.056t-4 3.36q-0.256 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.704 0.672-1.056 1.024-0.512 1.376-0.8 1.312-0.96 2.048-2.4t0.736-3.104-0.736-3.104-2.048-2.4q-0.352-0.288-1.376-0.8-0.672-0.352-0.672-1.056 0-0.448 0.32-0.8t0.8-0.352q0.224 0 0.48 0.096 2.496 1.056 4 3.36t1.536 5.056zM29.728 16q0 4.096-2.272 7.552t-6.048 5.056q-0.224 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.64 0.704-1.056 0.128-0.064 0.384-0.192t0.416-0.192q0.8-0.448 1.44-0.896 2.208-1.632 3.456-4.064t1.216-5.152-1.216-5.152-3.456-4.064q-0.64-0.448-1.44-0.896-0.128-0.096-0.416-0.192t-0.384-0.192q-0.704-0.416-0.704-1.056 0-0.448 0.32-0.8t0.832-0.352q0.224 0 0.448 0.096 3.776 1.632 6.048 5.056t2.272 7.552z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -34,18 +34,27 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-list {
|
||||
.aplayer-withlist {
|
||||
&.aplayer {
|
||||
.aplayer-info {
|
||||
border-bottom: 1px solid #e9e9e9;
|
||||
}
|
||||
|
||||
.aplayer-list {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.aplayer-icon-menu {
|
||||
display: inline !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer {
|
||||
background: #fff;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
margin: 5px;
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.07), 0 1px 5px 0 rgba(0, 0, 0, 0.1);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
@@ -55,6 +64,39 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
path,
|
||||
circle {
|
||||
fill: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-mobile {
|
||||
.aplayer-icon-volume-down {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-arrow {
|
||||
.aplayer-icon-order,
|
||||
.aplayer-icon-loop {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-loading {
|
||||
.aplayer-info .aplayer-controller .aplayer-loading-icon {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played .aplayer-thumb {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-icon {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
@@ -69,7 +111,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
margin: 0;
|
||||
display: inline;
|
||||
|
||||
.aplayer-fill {
|
||||
path {
|
||||
transition: all .2s ease-in-out;
|
||||
}
|
||||
}
|
||||
@@ -83,24 +125,25 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
float: left;
|
||||
height: $aplayer-height;
|
||||
width: $aplayer-height;
|
||||
background-image: url(./default.jpg);
|
||||
background-size: 100%;
|
||||
background-image: url(data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAeAAD/4QMfaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjYtYzA2NyA3OS4xNTc3NDcsIDIwMTUvMDMvMzAtMjM6NDA6NDIgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjE2NjQ3NUZBM0Y4RDExRTY4NzJCRDdCNkZCQTQ0MjNBIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjE2NjQ3NUY5M0Y4RDExRTY4NzJCRDdCNkZCQTQ0MjNBIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSI5OENEMEFFRjM0NTI1NjE0NEREQkU4RjkxRjAwNjM3NiIgc3RSZWY6ZG9jdW1lbnRJRD0iOThDRDBBRUYzNDUyNTYxNDREREJFOEY5MUYwMDYzNzYiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz7/7gAOQWRvYmUAZMAAAAAB/9sAhAAQCwsLDAsQDAwQFw8NDxcbFBAQFBsfFxcXFxcfHhcaGhoaFx4eIyUnJSMeLy8zMy8vQEBAQEBAQEBAQEBAQEBAAREPDxETERUSEhUUERQRFBoUFhYUGiYaGhwaGiYwIx4eHh4jMCsuJycnLis1NTAwNTVAQD9AQEBAQEBAQEBAQED/wAARCABkAGQDASIAAhEBAxEB/8QAgwAAAgIDAQAAAAAAAAAAAAAAAAYBBQIDBAcBAQEBAAAAAAAAAAAAAAAAAAABAhAAAQIEBAEJBgMHBQAAAAAAAQIDABEEBSExEgZBUWFxgaGxIhMUkTJCUmIVI0MWwdHh8XKSsvCCojNzEQEBAQEBAQEBAAAAAAAAAAAAAREhMVFBYf/aAAwDAQACEQMRAD8AaJ8vCJEYTjIZxtlIicc40VFZS0idVS6lpP1HE9Aind3dSrWWbdTPVruXgSQn98Awd0SBC+mp3fVYtUjFGk5F5U1S6Me6Mvtu6ncXbo01zNtzl2CJovwZxML/ANl3DwvZn/5fxiPt+72sWbkw/Lg4jTP/AImGhhiYWlXXdlD4q23IqWh7zlOZ/wCGrujpt+7bTWKDTijSvEy0O4CfJqy9sNMXmWMTECRExjzxMUEEEEBxLcbbQXHVBCEialKMgBFBU7jqax/0dmbU64fzJYy+aZwSOcxT7kvdPXVJpU6jTU5IC0HBauKucDhF7tS3ejolVJK51UlJQrCSRkeuJqppdspcV593dNU8cS0kkNjpPvKi8ZaZp2w3TtpabGSUAJHZEgzjXUVdPStebUOBpE5AnieQDieiKjeYyELVVva3ML0IZddI44IHaZxtod52upcDbqV0ylGSVLkUTP1JyibDDBOJxzjTUF8UzqqdIVUBtRZByK9J09seb1lzuKawuIqngRLSorUDMZ6k8DPMSwhaSPTwSDFbd7Bb7s2rzkBupl4KlIksH6vmHTE2GucuNqp6p3/tIKXCOKknST1xYgZDlihPsNxrLTXItFevXTuLU02omZadQZFP9Jw9ohxjz2tfF03GhFKdQXV6kqHINCJ/2tTj0KYJiQow6oIJY5QRR5hYLM5cK9KHkFNO1JbxIImOCeuPREyAAAkAJARyW63s26n8hlSnATqUtZmonnlKOucokhQtxDTa3XTpbbSVrVyJSNRhFq6usvNyap0K0v1JA5mG1YhtPJJOKzxOENG5HS3Yq1ScyhKSOZS0pPZCts8+ZfQtWK/LcUOk/wA4X3FhwoLJbKBgMtMIWZeN1xKVqWecqB9kJm7aKlo7wpulQGm3G0OKbT7qVKmDIcAZTh/LiW0KW4oJQgFS1HAAJEyTHnb6ndxX5XlAgVCwlH0MoEpnoSJwpD5ZFrXZ6JThOtTKJk9GHZCxvZmn9YHkJSh1KGw6QAC4p0uEauUhKIcmW0NNIaQJIbSEp5kpEhHntyqV3q7hlkzFQ/4T9ODSPYhM+uFI7rbZ9zU1EzXWuoGl5Ic9Pq0nH6XPAZ9MY1+6r2hh+3VjKGKojQtwApWlKhjhMjEcYZrzcW7JavMaA1pAZpUn5pSB6EgThT2xaTeLi5U1ZLjLJ8x4qzccUZhJ7zE/g6dlrtNO+t+pfSisUNDKF+EJScyFHCZh5BEpgzB4xR3TaVqr0lTKBR1BEw42JIJ+tvL2ShaZuN62xWejqZuMiRLKjqQtB+JpXD/U4vh69BxnKCK/73Qfa/uus+m0z+rVl5cvmnhBFRsHLyxIkrolGIMhKJSchAcl4pzVWmsYAmtbSijnUjxp7UwibdrEUd4pnlnS2olCycgFjTjHo4VHm9/paeku1QxTKCmtWrSPyyrFTf8AtiX6sW+5dwmtV9st5K2SoJdWnEuqnghP0z9sXe2rCLXTl18A1rwGvj5afkH7YoNov2aneW7WLCK2cmVOYISn6Tlq6Yaau+2mkaLjlU2ogYNtkLWo8JBMJ9GndFzFBanEpMqipmy1ygKHjV1J74odkW4u1blwWPw6ceW0eVxYx9ie+K+oeuG57sA0iXwtozSy1P3lHvh+t1AzbqNqkY9xsYq4qUcVKPSYe0/C9vxp9VPRvAEstqWlZGSVLCdM+mRjn2Xd6KkS9R1K0sqcUFtuKwSrCRSTDg42262pp1CXGljStChqSoHlBigqdk2h5RUyt2mn8CSFo6tePbDO6Ll67W1hOtyrZSn+sHsGMJW6r3S3Z9hukQS3T6gHSJFZXLBIzlhFs3sO3pV+JVPLHIEoR2+KLm32C024hdMwPNGTrh1r6irLqh2pwvfp+4fpPydJ9T5vqfT/ABaJadMvmljKCHLjxnBDDXDPGXGJmTkcogETMshjyxlPhFGqqfVT0b9QMSy2twDnSkkdsJtoomK7cC2KoB1plKtSVfmKT4ST0qUVQ7KbQ62th3xNuJUhY46VDSewwhvqrdvXsPrTqUMZ/C82fCVJP1dhiVYvKjY9vcVqpqhxgH8tQDgHQZpMRT7EokkF+qccHyISlufX4oubddKG5shymWCvNbRwWk84jtBMgeSGRNaKOgo7eyWaNoNIPvEYqUfqUcTHVOMRIxOKscooyBxg5eSIM5T48IkY/vgJOPVBOXOIBM80aKqspaNvzap1LaRlM4noGZgOjVBC5+sqX1ejyj6aUp6vxf6tGUuac4ImwxbAkKlEzBywjHGUgermiRPLhFGYJ48Y01tDSXBg09Y2HG5+E5KSZZoUMo2AgZRkDiBLDiIBQq9n3ClcL9pf80JxSkny3k9fuqjBvcu4bYfLuDBWBh+MgoV/eMDDoMyZ4RIM0kETT8pxETPi6WmN9UKhJ+ncQTnpIUP2R1p3jZCMVOJ5igxYu2q1vmbtGwvn0JB7JRznbthOJoW8eQqHcqHU40K3nZAMFOKllJB/bHI9vuiTMU9M44o/MQkdk4tUbdsaDMUTXXNXeY6maChp5eTTNI5ClCQe6HThWN+3Rc/Bb6UtIV8SUH/NeEZ02zrhWOefdqognNKT5izzajgIbpz7gIkfzhhqs/TFk9J6b0w05+ZM+ZPl1wRay9kEUV4y+qXZGachyc8EEBKeMAnLCf8ACCCAzE5d8ZHMS64IIA7oy+HDqgggIEpYdUZJnpE84IICeScSJYwQQE8IIIID/9k=);
|
||||
background-size: cover;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover .aplayer-button {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.aplayer-button {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
opacity: 0.8;
|
||||
cursor: pointer;
|
||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
transition: all 0.1s ease;
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.aplayer-fill {
|
||||
path {
|
||||
fill: #fff;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +159,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
bottom: 50%;
|
||||
right: 50%;
|
||||
margin: 0 -15px -15px 0;
|
||||
.aplayer-icon-play {
|
||||
svg {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 4px;
|
||||
@@ -131,7 +174,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
border: 2px solid #fff;
|
||||
bottom: 4px;
|
||||
right: 4px;
|
||||
.aplayer-icon-pause {
|
||||
svg {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
@@ -176,6 +219,12 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
cursor: pointer !important;
|
||||
flex: 1;
|
||||
|
||||
&:hover {
|
||||
.aplayer-bar .aplayer-played .aplayer-thumb {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-bar {
|
||||
position: relative;
|
||||
height: 2px;
|
||||
@@ -205,11 +254,12 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
right: 5px;
|
||||
margin-top: -4px;
|
||||
margin-right: -10px;
|
||||
height: 8px;
|
||||
width: 8px;
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
cursor: pointer !important;
|
||||
cursor: pointer;
|
||||
transition: all .3s ease-in-out;
|
||||
transform: scale(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +268,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
.aplayer-time {
|
||||
position: relative;
|
||||
right: 0;
|
||||
bottom: 3px;
|
||||
bottom: 4px;
|
||||
height: 17px;
|
||||
color: #999;
|
||||
font-size: 11px;
|
||||
@@ -232,19 +282,23 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
.aplayer-fill {
|
||||
path {
|
||||
fill: #666;
|
||||
}
|
||||
|
||||
&.aplayer-icon-mode {
|
||||
margin-right: 4px;
|
||||
&.aplayer-icon-loop {
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.aplayer-fill {
|
||||
path {
|
||||
fill: #000;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-icon-menu {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-time-narrow {
|
||||
@@ -265,17 +319,22 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
cursor: pointer !important;
|
||||
|
||||
&:hover .aplayer-volume-bar-wrap {
|
||||
display: block;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.aplayer-volume-bar-wrap {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 15px;
|
||||
right: -3px;
|
||||
width: 25px;
|
||||
height: 40px;
|
||||
height: 0;
|
||||
z-index: 99;
|
||||
overflow: hidden;
|
||||
transition: all .2s ease-in-out;
|
||||
|
||||
&.aplayer-volume-bar-wrap-active {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.aplayer-volume-bar {
|
||||
position: absolute;
|
||||
@@ -284,6 +343,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
width: 5px;
|
||||
height: 35px;
|
||||
background: #aaa;
|
||||
border-radius: 2.5px;
|
||||
overflow: hidden;
|
||||
|
||||
.aplayer-volume {
|
||||
position: absolute;
|
||||
@@ -295,6 +356,15 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-loading-icon {
|
||||
display: none;
|
||||
|
||||
svg {
|
||||
position: absolute;
|
||||
animation: rotate 1s linear infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +372,6 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
display: none;
|
||||
position: relative;
|
||||
height: $lrc-height;
|
||||
background: #fff;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
margin: -10px 0 7px;
|
||||
@@ -350,6 +419,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
|
||||
&.aplayer-lrc-current {
|
||||
opacity: 1;
|
||||
overflow: visible;
|
||||
height: initial !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,6 +436,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
overflow: auto;
|
||||
transition: all 0.5s ease;
|
||||
will-change: height;
|
||||
display: none;
|
||||
|
||||
&.aplayer-list-hide {
|
||||
height: 0 !important;
|
||||
@@ -399,6 +471,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
|
||||
&:first-child {
|
||||
border-top: none;
|
||||
@@ -443,4 +516,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
@keyframes aplayer-roll {
|
||||
0%{left:0}
|
||||
100%{left: -100%}
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
0% {
|
||||
transform: rotate(0)
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg)
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,27 @@
|
||||
class Bar {
|
||||
constructor (template) {
|
||||
this.elements = {};
|
||||
this.elements.volume = template.volume;
|
||||
this.elements.played = template.played;
|
||||
this.elements.loaded = template.loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update progress
|
||||
*
|
||||
* @param {String} type - Point out which bar it is
|
||||
* @param {Number} percentage
|
||||
* @param {String} direction - Point out the direction of this bar, Should be height or width
|
||||
*/
|
||||
set (type, percentage, direction) {
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.elements[type].style[direction] = percentage * 100 + '%';
|
||||
}
|
||||
|
||||
get (type, direction) {
|
||||
return parseFloat(this.elements[type].style[direction]) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
export default Bar;
|
||||
@@ -0,0 +1,168 @@
|
||||
import utils from './utils';
|
||||
import Icons from './icons';
|
||||
|
||||
class Controller {
|
||||
constructor (player) {
|
||||
this.player = player;
|
||||
|
||||
this.initPlayButton();
|
||||
this.initList();
|
||||
this.initPlayBar();
|
||||
if (this.player.isMultiple()) {
|
||||
this.initOrderButton();
|
||||
}
|
||||
this.initLoopButton();
|
||||
this.initMenuButton();
|
||||
if (!utils.isMobile) {
|
||||
this.initVolumeButton();
|
||||
}
|
||||
}
|
||||
|
||||
initPlayButton () {
|
||||
this.player.template.pic.addEventListener('click', () => {
|
||||
this.player.toggle();
|
||||
});
|
||||
}
|
||||
|
||||
initList () {
|
||||
this.player.template.list.addEventListener('click', (e) => {
|
||||
let target;
|
||||
if (e.target.tagName.toUpperCase() === 'LI') {
|
||||
target = e.target;
|
||||
}
|
||||
else {
|
||||
target = e.target.parentElement;
|
||||
}
|
||||
const audioIndex = parseInt(target.getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
||||
if (audioIndex !== this.player.playIndex) {
|
||||
this.player.switchAudio(audioIndex);
|
||||
this.player.play();
|
||||
}
|
||||
else {
|
||||
this.player.toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initPlayBar () {
|
||||
const thumbMove = (e) => {
|
||||
let percentage = ((e.clientX || e.changedTouches[0].clientX) - utils.getElementViewLeft(this.player.template.barWrap)) / this.player.template.barWrap.clientWidth;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.bar.set('played', percentage, 'width');
|
||||
this.player.lrc && this.player.lrc.update(percentage * this.player.audio.duration);
|
||||
this.player.template.ptime.innerHTML = utils.secondToTime(percentage * this.player.audio.duration);
|
||||
};
|
||||
|
||||
const thumbUp = (e) => {
|
||||
document.removeEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
document.removeEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
let percentage = ((e.clientX || e.changedTouches[0].clientX) - utils.getElementViewLeft(this.player.template.barWrap)) / this.player.template.barWrap.clientWidth;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.bar.set('played', percentage, 'width');
|
||||
this.player.seek(this.player.bar.get('played', 'width') * this.player.audio.duration);
|
||||
this.player.timer.enable('progress');
|
||||
};
|
||||
|
||||
this.player.template.barWrap.addEventListener(utils.nameMap.dragStart, () => {
|
||||
this.player.timer.disable('progress');
|
||||
document.addEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
document.addEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
});
|
||||
}
|
||||
|
||||
initVolumeButton () {
|
||||
this.player.template.volumeButton.addEventListener('click', () => {
|
||||
if (this.player.audio.muted) {
|
||||
this.player.audio.muted = false;
|
||||
this.player.switchVolumeIcon();
|
||||
this.player.bar.set('volume', this.player.volume(), 'height');
|
||||
}
|
||||
else {
|
||||
this.player.audio.muted = true;
|
||||
this.player.switchVolumeIcon();
|
||||
this.player.bar.set('volume', 0, 'height');
|
||||
}
|
||||
});
|
||||
|
||||
const thumbMove = (e) => {
|
||||
let percentage = 1 - ((e.clientY || e.changedTouches[0].clientY) - utils.getElementViewTop(this.player.template.volumeBar)) / this.player.template.volumeBar.clientHeight;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.volume(percentage);
|
||||
};
|
||||
|
||||
const thumbUp = (e) => {
|
||||
this.player.template.volumeBarWrap.classList.remove('aplayer-volume-bar-wrap-active');
|
||||
document.removeEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
document.removeEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
let percentage = 1 - ((e.clientY || e.changedTouches[0].clientY) - utils.getElementViewTop(this.player.template.volumeBar)) / this.player.template.volumeBar.clientHeight;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.volume(percentage);
|
||||
};
|
||||
|
||||
this.player.template.volumeBarWrap.addEventListener(utils.nameMap.dragStart, () => {
|
||||
this.player.template.volumeBarWrap.classList.add('aplayer-volume-bar-wrap-active');
|
||||
document.addEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
document.addEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
});
|
||||
}
|
||||
|
||||
initOrderButton () {
|
||||
this.player.template.order.addEventListener('click', () => {
|
||||
if (this.player.options.order === 'list') {
|
||||
this.player.options.order = 'random';
|
||||
this.player.template.order.innerHTML = Icons.orderRandom;
|
||||
}
|
||||
else if (this.player.options.order === 'random') {
|
||||
this.player.options.order = 'list';
|
||||
this.player.template.order.innerHTML = Icons.orderList;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initLoopButton () {
|
||||
this.player.template.loop.addEventListener('click', () => {
|
||||
if (this.player.isMultiple()) {
|
||||
if (this.player.options.loop === 'one') {
|
||||
this.player.options.loop = 'none';
|
||||
this.player.template.loop.innerHTML = Icons.loopNone;
|
||||
}
|
||||
else if (this.player.options.loop === 'none') {
|
||||
this.player.options.loop = 'all';
|
||||
this.player.template.loop.innerHTML = Icons.loopAll;
|
||||
}
|
||||
else if (this.player.options.loop === 'all') {
|
||||
this.player.options.loop = 'one';
|
||||
this.player.template.loop.innerHTML = Icons.loopOne;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.player.options.loop === 'one' || this.player.options.loop === 'all') {
|
||||
this.player.options.loop = 'none';
|
||||
this.player.template.loop.innerHTML = Icons.loopNone;
|
||||
}
|
||||
else if (this.player.options.loop === 'none') {
|
||||
this.player.options.loop = 'all';
|
||||
this.player.template.loop.innerHTML = Icons.loopAll;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initMenuButton () {
|
||||
this.player.template.list.style.height = 33 * this.player.options.audio.length - 1 + 'px';
|
||||
this.player.template.menu.addEventListener('click', () => {
|
||||
if (!this.player.template.list.classList.contains('aplayer-list-hide')) {
|
||||
this.player.template.list.classList.add('aplayer-list-hide');
|
||||
}
|
||||
else {
|
||||
this.player.template.list.classList.remove('aplayer-list-hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Controller;
|
||||
@@ -0,0 +1,46 @@
|
||||
class Events {
|
||||
constructor () {
|
||||
this.events = {};
|
||||
|
||||
this.audioEvents = [
|
||||
'abort', 'canplay', 'canplaythrough', 'durationchange', 'emptied', 'ended', 'error',
|
||||
'loadeddata', 'loadedmetadata', 'loadstart', 'mozaudioavailable', 'pause', 'play',
|
||||
'playing', 'progress', 'ratechange', 'seeked', 'seeking', 'stalled', 'suspend',
|
||||
'timeupdate', 'volumechange', 'waiting'
|
||||
];
|
||||
this.playerEvents = [
|
||||
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
|
||||
];
|
||||
}
|
||||
|
||||
on (name, callback) {
|
||||
if (this.type(name) && typeof callback === 'function') {
|
||||
if (!this.events[name]) {
|
||||
this.events[name] = [];
|
||||
}
|
||||
this.events[name].push(callback);
|
||||
}
|
||||
}
|
||||
|
||||
trigger (name, info) {
|
||||
if (this.events[name] && this.events[name].length) {
|
||||
for (let i = 0; i < this.events[name].length; i++) {
|
||||
this.events[name][i](info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type (name) {
|
||||
if (this.playerEvents.indexOf(name) !== -1) {
|
||||
return 'player';
|
||||
}
|
||||
else if (this.audioEvents.indexOf(name) !== -1) {
|
||||
return 'audio';
|
||||
}
|
||||
|
||||
console.error(`Unknown event name: ${name}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default Events;
|
||||
@@ -0,0 +1,29 @@
|
||||
import play from '../assets/play.svg';
|
||||
import pause from '../assets/pause.svg';
|
||||
import volumeUp from '../assets/volume-up.svg';
|
||||
import volumeDown from '../assets/volume-down.svg';
|
||||
import volumeOff from '../assets/volume-off.svg';
|
||||
import orderRandom from '../assets/order-random.svg';
|
||||
import orderList from '../assets/order-list.svg';
|
||||
import menu from '../assets/menu.svg';
|
||||
import loopAll from '../assets/loop-all.svg';
|
||||
import loopOne from '../assets/loop-one.svg';
|
||||
import loopNone from '../assets/loop-none.svg';
|
||||
import loading from '../assets/loading.svg';
|
||||
|
||||
const Icons = {
|
||||
play: play,
|
||||
pause: pause,
|
||||
volumeUp: volumeUp,
|
||||
volumeDown: volumeDown,
|
||||
volumeOff: volumeOff,
|
||||
orderRandom: orderRandom,
|
||||
orderList: orderList,
|
||||
menu: menu,
|
||||
loopAll: loopAll,
|
||||
loopOne: loopOne,
|
||||
loopNone: loopNone,
|
||||
loading: loading,
|
||||
};
|
||||
|
||||
export default Icons;
|
||||
@@ -0,0 +1,7 @@
|
||||
import '../css/index.scss';
|
||||
import APlayer from './player';
|
||||
|
||||
/* global APLAYER_VERSION GIT_HASH */
|
||||
console.log(`${'\n'} %c APlayer v${APLAYER_VERSION} ${GIT_HASH} %c http://aplayer.js.org ${'\n'}${'\n'}`, 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;');
|
||||
|
||||
export default APlayer;
|
||||
@@ -0,0 +1,118 @@
|
||||
import tplLrc from '../template/lrc.art';
|
||||
|
||||
class Lrc {
|
||||
constructor (options) {
|
||||
this.container = options.container;
|
||||
this.async = options.async;
|
||||
this.player = options.player;
|
||||
this.content = options.content;
|
||||
this.parsed = [];
|
||||
this.index = 0;
|
||||
this.current = [];
|
||||
}
|
||||
|
||||
update (currentTime = this.player.audio.currentTime) {
|
||||
if (this.index > this.current.length - 1 || currentTime < this.current[this.index][0] || (!this.current[this.index + 1] || currentTime >= this.current[this.index + 1][0])) {
|
||||
for (let i = 0; i < this.current.length; i++) {
|
||||
if (currentTime >= this.current[i][0] && (!this.current[i + 1] || currentTime < this.current[i + 1][0])) {
|
||||
this.index = i;
|
||||
this.container.style.transform = `translateY(${-this.index * 16}px)`;
|
||||
this.container.style.webkitTransform = `translateY(${-this.index * 16}px)`;
|
||||
this.container.getElementsByClassName('aplayer-lrc-current')[0].classList.remove('aplayer-lrc-current');
|
||||
this.container.getElementsByTagName('p')[i].classList.add('aplayer-lrc-current');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (index) {
|
||||
if (!this.parsed[index]) {
|
||||
if (!this.async) {
|
||||
if (this.content[index]) {
|
||||
this.parsed[index] = this.parse(this.content[index]);
|
||||
}
|
||||
else {
|
||||
this.parsed[index] = [['00:00', 'Not available']];
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.parsed[index] = [['00:00', 'Loading']];
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
|
||||
this.parsed[index] = this.parse(xhr.responseText);
|
||||
}
|
||||
else {
|
||||
console.log('Request was unsuccessful: ' + xhr.status);
|
||||
this.parsed[index] = [['00:00', 'Not available']];
|
||||
}
|
||||
|
||||
this.container.innerHTML = tplLrc({
|
||||
lyrics: this.parsed[index]
|
||||
});
|
||||
this.update(0);
|
||||
this.current = this.parsed[index];
|
||||
}
|
||||
};
|
||||
const apiurl = this.content[index];
|
||||
xhr.open('get', apiurl, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
}
|
||||
|
||||
this.container.innerHTML = tplLrc({
|
||||
lyrics: this.parsed[index]
|
||||
});
|
||||
this.update(0);
|
||||
this.current = this.parsed[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse lrc, suppose multiple time tag
|
||||
*
|
||||
* @param {String} lrc_s - Format:
|
||||
* [mm:ss]lyric
|
||||
* [mm:ss.xx]lyric
|
||||
* [mm:ss.xxx]lyric
|
||||
* [mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
|
||||
* [mm:ss.xx]<mm:ss.xx>lyric
|
||||
*
|
||||
* @return {String} [[time, text], [time, text], [time, text], ...]
|
||||
*/
|
||||
parse (lrc_s) {
|
||||
if (lrc_s) {
|
||||
lrc_s = lrc_s.replace(/([^\]^\n])\[/g, (match, p1) => p1 + '\n[');
|
||||
const lyric = lrc_s.split('\n');
|
||||
const lrc = [];
|
||||
const lyricLen = lyric.length;
|
||||
for (let i = 0; i < lyricLen; i++) {
|
||||
// match lrc time
|
||||
const lrcTimes = lyric[i].match(/\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g);
|
||||
// match lrc text
|
||||
const lrcText = lyric[i].replace(/.*\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g, '').replace(/<(\d{2}):(\d{2})(\.(\d{2,3}))?>/g, '').replace(/^\s+|\s+$/g, '');
|
||||
|
||||
if (lrcTimes) {
|
||||
// handle multiple time tag
|
||||
const timeLen = lrcTimes.length;
|
||||
for (let j = 0; j < timeLen; j++) {
|
||||
const oneTime = /\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/.exec(lrcTimes[j]);
|
||||
const min2sec = oneTime[1] * 60;
|
||||
const sec2sec = parseInt(oneTime[2]);
|
||||
const msec2sec = oneTime[4] ? parseInt(oneTime[4]) / ((oneTime[4] + '').length === 2 ? 100 : 1000) : 0;
|
||||
const lrcTime = min2sec + sec2sec + msec2sec;
|
||||
lrc.push([lrcTime, lrcText]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// sort by time
|
||||
lrc.sort((a, b) => a[0] - b[0]);
|
||||
return lrc;
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Lrc;
|
||||
@@ -0,0 +1,41 @@
|
||||
export default (options) => {
|
||||
|
||||
// default options
|
||||
const defaultOption = {
|
||||
container: options.element || document.getElementsByClassName('aplayer')[0],
|
||||
mini: options.narrow || false,
|
||||
autoplay: false,
|
||||
mutex: true,
|
||||
lrc: options.showlrc || 0,
|
||||
preload: 'auto',
|
||||
theme: '#b7daff',
|
||||
loop: 'all',
|
||||
order: 'list',
|
||||
volume: 0.7,
|
||||
listFolded: false,
|
||||
listMaxHeight: options.listmaxheight,
|
||||
audio: options.music
|
||||
};
|
||||
for (const defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
|
||||
options[defaultKey] = defaultOption[defaultKey];
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(options.audio) !== '[object Array]') {
|
||||
options.audio = [options.audio];
|
||||
}
|
||||
|
||||
options.audio.map((item) => {
|
||||
item.name = item.name || item.title;
|
||||
item.artist = item.artist || item.author;
|
||||
item.cover = item.cover || item.pic;
|
||||
return item;
|
||||
});
|
||||
|
||||
if (options.audio.length <= 1 && options.loop === 'one') {
|
||||
options.loop = 'all';
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
@@ -0,0 +1,464 @@
|
||||
import Promise from 'promise-polyfill';
|
||||
|
||||
import utils from './utils';
|
||||
import Icons from './icons';
|
||||
import handleOption from './options';
|
||||
import Template from './template';
|
||||
import Bar from './bar';
|
||||
import User from './user';
|
||||
import Lrc from './lrc';
|
||||
import Controller from './controller';
|
||||
import Timer from './timer';
|
||||
import Events from './events';
|
||||
|
||||
const instances = [];
|
||||
|
||||
class APlayer {
|
||||
|
||||
/**
|
||||
* APlayer constructor function
|
||||
*
|
||||
* @param {Object} options - See README
|
||||
* @constructor
|
||||
*/
|
||||
constructor (options) {
|
||||
this.options = handleOption(options);
|
||||
this.container = this.options.container;
|
||||
this.playIndex = 0;
|
||||
this.paused = true;
|
||||
this.playedPromise = Promise.resolve();
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
|
||||
this.container.classList.add('aplayer');
|
||||
if (this.options.lrc) {
|
||||
this.container.classList.add('aplayer-withlrc');
|
||||
}
|
||||
if (this.options.audio.length > 1) {
|
||||
this.container.classList.add('aplayer-withlist');
|
||||
}
|
||||
if (utils.isMobile) {
|
||||
this.container.classList.add('aplayer-mobile');
|
||||
}
|
||||
this.arrow = this.container.offsetWidth <= 300;
|
||||
if (this.arrow) {
|
||||
this.container.classList.add('aplayer-arrow');
|
||||
}
|
||||
if (this.options.mini) {
|
||||
this.container.classList.add('aplayer-narrow');
|
||||
}
|
||||
|
||||
// save lrc
|
||||
this.container = this.options.container;
|
||||
if (this.options.lrc === 2 || this.options.lrc === true) {
|
||||
const lrcEle = this.container.getElementsByClassName('aplayer-lrc-content');
|
||||
for (let i = 0; i < lrcEle.length; i++) {
|
||||
if (this.options.audio[i]) {
|
||||
this.options.audio[i].lrc = lrcEle[i].innerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.template = new Template({
|
||||
container: this.container,
|
||||
options: this.options,
|
||||
randomOrder: this.randomOrder,
|
||||
});
|
||||
|
||||
if (this.template.info.offsetWidth < 200) {
|
||||
this.template.time.classList.add('aplayer-time-narrow');
|
||||
}
|
||||
|
||||
if (this.options.lrc) {
|
||||
this.lrc = new Lrc({
|
||||
container: this.template.lrc,
|
||||
async: this.options.lrc === 3,
|
||||
content: this.options.audio.map((item) => item.lrc),
|
||||
player: this,
|
||||
});
|
||||
}
|
||||
this.events = new Events();
|
||||
this.user = new User(this);
|
||||
this.bar = new Bar(this.template);
|
||||
this.controller = new Controller(this);
|
||||
this.timer = new Timer(this);
|
||||
|
||||
this.initAudio();
|
||||
if (this.options.order === 'random') {
|
||||
this.switchAudio(this.randomOrder[0]);
|
||||
}
|
||||
else {
|
||||
this.switchAudio(0);
|
||||
}
|
||||
|
||||
// autoplay
|
||||
if (this.options.autoplay) {
|
||||
this.play();
|
||||
}
|
||||
|
||||
instances.push(this);
|
||||
}
|
||||
|
||||
initAudio () {
|
||||
this.audio = document.createElement('audio');
|
||||
this.audio.preload = this.options.preload;
|
||||
|
||||
for (let i = 0; i < this.events.audioEvents.length; i++) {
|
||||
this.audio.addEventListener(this.events.audioEvents[i], () => {
|
||||
this.events.trigger(this.events.audioEvents[i]);
|
||||
});
|
||||
}
|
||||
|
||||
this.on('play', () => {
|
||||
if (this.paused) {
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.on('pause', () => {
|
||||
if (!this.paused) {
|
||||
this.pause();
|
||||
}
|
||||
});
|
||||
|
||||
// show audio time: the metadata has loaded or changed
|
||||
this.on('durationchange', () => {
|
||||
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.template.dtime.innerHTML = utils.secondToTime(this.audio.duration);
|
||||
}
|
||||
});
|
||||
|
||||
// show audio loaded bar: to inform interested parties of progress downloading the media
|
||||
this.on('progress', () => {
|
||||
const percentage = this.audio.buffered.length ? this.audio.buffered.end(this.audio.buffered.length - 1) / this.audio.duration : 0;
|
||||
this.bar.set('loaded', percentage, 'width');
|
||||
});
|
||||
|
||||
// audio download error: an error occurs
|
||||
this.on('error', () => {
|
||||
this.template.author.innerHTML = ` - Error happens ╥﹏╥`;
|
||||
});
|
||||
|
||||
// multiple audio play
|
||||
this.on('ended', () => {
|
||||
if (this.options.loop === 'none') {
|
||||
if (this.options.order === 'list') {
|
||||
if (this.playIndex < this.options.audio.length - 1) {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
if (this.randomOrder.indexOf(this.playIndex) < this.randomOrder.length - 1) {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.options.loop === 'one') {
|
||||
this.switchAudio(this.playIndex);
|
||||
this.play();
|
||||
}
|
||||
else if (this.options.loop === 'all') {
|
||||
if (this.options.order === 'list') {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
}
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.volume(this.user.get('volume'), true);
|
||||
}
|
||||
|
||||
switchAudio (index) {
|
||||
this.handlePlayPromise(() => {
|
||||
this.events.trigger('switchaudio', index);
|
||||
if (typeof index !== 'undefined') {
|
||||
this.playIndex = index;
|
||||
}
|
||||
|
||||
// set html
|
||||
if (this.options.audio[this.playIndex].cover) {
|
||||
this.template.pic.style.backgroundImage = `url('${this.options.audio[this.playIndex].cover}')`;
|
||||
}
|
||||
else {
|
||||
this.template.pic.style.backgroundImage = '';
|
||||
}
|
||||
this.template.title.innerHTML = this.options.audio[this.playIndex].name;
|
||||
this.template.author.innerHTML = this.options.audio[this.playIndex].artist ? ' - ' + this.options.audio[this.playIndex].artist : '';
|
||||
const light = this.container.getElementsByClassName('aplayer-list-light')[0];
|
||||
if (light) {
|
||||
light.classList.remove('aplayer-list-light');
|
||||
}
|
||||
this.container.querySelectorAll('.aplayer-list li')[this.playIndex].classList.add('aplayer-list-light');
|
||||
|
||||
this.template.list.scrollTop = this.playIndex * 33;
|
||||
|
||||
this.audio.src = this.options.audio[this.playIndex].url;
|
||||
this.seek(0);
|
||||
|
||||
let playPromise;
|
||||
if (!this.paused) {
|
||||
playPromise = Promise.resolve(this.audio.play()).catch((err) => {
|
||||
console.error(err);
|
||||
this.pause();
|
||||
});
|
||||
}
|
||||
|
||||
this.lrc && this.lrc.switch(this.playIndex);
|
||||
|
||||
// set duration time
|
||||
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.template.dtime.innerHTML = this.audio.duration ? utils.secondToTime(this.audio.duration) : '00:00';
|
||||
}
|
||||
|
||||
return playPromise;
|
||||
});
|
||||
}
|
||||
|
||||
seek (time) {
|
||||
time = Math.max(time, 0);
|
||||
if (this.audio.duration) {
|
||||
time = Math.min(time, this.audio.duration);
|
||||
}
|
||||
|
||||
this.audio.currentTime = time;
|
||||
|
||||
if (isNaN(this.audio.duration)) {
|
||||
this.bar.set('played', 0, 'width');
|
||||
}
|
||||
else {
|
||||
this.bar.set('played', time / this.audio.duration, 'width');
|
||||
}
|
||||
this.template.ptime.innerHTML = utils.secondToTime(time);
|
||||
}
|
||||
|
||||
play () {
|
||||
this.handlePlayPromise(() => {
|
||||
if (this.paused) {
|
||||
this.paused = false;
|
||||
this.template.button.classList.remove('aplayer-play');
|
||||
this.template.button.classList.add('aplayer-pause');
|
||||
this.template.button.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
this.template.button.innerHTML = Icons.pause;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
const playPromise = Promise.resolve(this.audio.play()).catch((err) => {
|
||||
console.error(err);
|
||||
this.pause();
|
||||
});
|
||||
|
||||
this.timer.enable('loading');
|
||||
this.timer.enable('progress');
|
||||
|
||||
if (this.options.mutex) {
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
if (this !== instances[i]) {
|
||||
instances[i].pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return playPromise;
|
||||
});
|
||||
}
|
||||
|
||||
pause () {
|
||||
this.handlePlayPromise(() => {
|
||||
if (!this.paused) {
|
||||
this.paused = true;
|
||||
|
||||
this.template.button.classList.remove('aplayer-pause');
|
||||
this.template.button.classList.add('aplayer-play');
|
||||
this.template.button.innerHTML = '';
|
||||
setTimeout(() => {
|
||||
this.template.button.innerHTML = Icons.play;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
this.audio.pause();
|
||||
|
||||
this.timer.disable('loading');
|
||||
this.timer.disable('progress');
|
||||
});
|
||||
}
|
||||
|
||||
switchVolumeIcon () {
|
||||
if (this.volume() >= 0.95) {
|
||||
this.template.volumeButton.innerHTML = Icons.volumeUp;
|
||||
}
|
||||
else if (this.volume() > 0) {
|
||||
this.template.volumeButton.innerHTML = Icons.volumeDown;
|
||||
}
|
||||
else {
|
||||
this.template.volumeButton.innerHTML = Icons.volumeOff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set volume
|
||||
*/
|
||||
volume (percentage, nostorage) {
|
||||
percentage = parseFloat(percentage);
|
||||
if (!isNaN(percentage)) {
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.bar.set('volume', percentage, 'height');
|
||||
if (!nostorage) {
|
||||
this.user.set('volume', percentage);
|
||||
}
|
||||
|
||||
this.audio.volume = percentage;
|
||||
if (this.audio.muted) {
|
||||
this.audio.muted = false;
|
||||
}
|
||||
|
||||
this.switchVolumeIcon();
|
||||
}
|
||||
|
||||
return this.audio.muted ? 0 : this.audio.volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* bind events
|
||||
*/
|
||||
on (name, callback) {
|
||||
this.events.on(name, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle between play and pause
|
||||
*/
|
||||
toggle () {
|
||||
if (this.template.button.classList.contains('aplayer-play')) {
|
||||
this.play();
|
||||
}
|
||||
else if (this.template.button.classList.contains('aplayer-pause')) {
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get whether multiple audio definitions are loaded
|
||||
*/
|
||||
isMultiple () {
|
||||
return this.options.audio.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* get next random number
|
||||
*/
|
||||
nextRandomNum () {
|
||||
if (this.isMultiple()) {
|
||||
const index = this.randomOrder.indexOf(this.playIndex);
|
||||
if (index === this.randomOrder.length - 1) {
|
||||
return this.randomOrder[0];
|
||||
}
|
||||
else {
|
||||
return this.randomOrder[index + 1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add audio dynamically
|
||||
*
|
||||
* @param {Array} newMusic
|
||||
*/
|
||||
addAudio (newMusic) {
|
||||
this.events.trigger('addaudio', newMusic);
|
||||
const wasSingle = !this.isMultiple();
|
||||
|
||||
this.options.audio = this.options.audio.concat(newMusic);
|
||||
|
||||
let newItemHTML = ``;
|
||||
for (let i = 0; i < newMusic.length; i++) {
|
||||
newItemHTML += `
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: ${this.options.theme};"></span>
|
||||
<span class="aplayer-list-index">${this.options.audio.length - newMusic.length + i + 1}</span>
|
||||
<span class="aplayer-list-title">${newMusic[i].name}</span>
|
||||
<span class="aplayer-list-author">${newMusic[i].artist}</span>
|
||||
</li>`;
|
||||
}
|
||||
this.template.listOl.innerHTML += newItemHTML;
|
||||
|
||||
if (wasSingle && this.isMultiple()) {
|
||||
this.container.classList.add('aplayer-withlist');
|
||||
this.audio.loop = false;
|
||||
}
|
||||
const songListLength = this.container.querySelectorAll('.aplayer-list li').length;
|
||||
this.template.list.style.height = songListLength * 33 - 1 + 'px';
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove song from playlist
|
||||
*/
|
||||
removeAudio (index) {
|
||||
this.events.trigger('removeaudio', index);
|
||||
if (this.options.audio[index] && this.options.audio.length > 1) {
|
||||
const list = this.container.querySelectorAll('.aplayer-list li');
|
||||
|
||||
this.options.audio.splice(index, 1);
|
||||
|
||||
if (index === this.playIndex) {
|
||||
if (this.options.audio[index + 1]) {
|
||||
this.switchAudio(index);
|
||||
}
|
||||
else {
|
||||
this.switchAudio(index - 1);
|
||||
}
|
||||
}
|
||||
if (this.playIndex > index) {
|
||||
this.playIndex--;
|
||||
}
|
||||
|
||||
list[index].remove();
|
||||
for (let i = index; i < list.length; i++) {
|
||||
list[i].getElementsByClassName('aplayer-list-index')[0].textContent = i;
|
||||
}
|
||||
if (this.options.audio.length === 1) {
|
||||
this.container.classList.remove('aplayer-withlist');
|
||||
}
|
||||
this.template.list.style.height = parseInt(this.template.list.style.height, 10) - 33 + 'px';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy this player
|
||||
*/
|
||||
destroy () {
|
||||
instances.splice(instances.indexOf(this), 1);
|
||||
this.pause();
|
||||
this.container.innerHTML = '';
|
||||
this.audio.src = '';
|
||||
this.timer.destroy();
|
||||
this.events.trigger('destroy');
|
||||
}
|
||||
|
||||
handlePlayPromise (callback) {
|
||||
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default APlayer;
|
||||
@@ -0,0 +1,52 @@
|
||||
import Icons from './icons';
|
||||
import tplPlayer from '../template/player.art';
|
||||
|
||||
class Template {
|
||||
constructor (options) {
|
||||
this.container = options.container;
|
||||
this.options = options.options;
|
||||
this.randomOrder = options.randomOrder;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
let cover;
|
||||
if (this.options.order === 'random') {
|
||||
cover = this.options.audio[this.randomOrder[0]].cover;
|
||||
}
|
||||
else {
|
||||
cover = this.options.audio[0].cover;
|
||||
}
|
||||
|
||||
this.container.innerHTML = tplPlayer({
|
||||
options: this.options,
|
||||
icons: Icons,
|
||||
cover: cover,
|
||||
});
|
||||
|
||||
this.lrc = this.container.querySelector('.aplayer-lrc-contents');
|
||||
this.ptime = this.container.querySelector('.aplayer-ptime');
|
||||
this.info = this.container.querySelector('.aplayer-info');
|
||||
this.time = this.container.querySelector('.aplayer-time');
|
||||
this.barWrap = this.container.querySelector('.aplayer-bar-wrap');
|
||||
this.button = this.container.querySelector('.aplayer-button');
|
||||
this.list = this.container.querySelector('.aplayer-list');
|
||||
this.listOl = this.container.querySelector('.aplayer-list ol');
|
||||
this.played = this.container.querySelector('.aplayer-played');
|
||||
this.loaded = this.container.querySelector('.aplayer-loaded');
|
||||
this.thumb = this.container.querySelector('.aplayer-thumb');
|
||||
this.volume = this.container.querySelector('.aplayer-volume');
|
||||
this.volumeBar = this.container.querySelector('.aplayer-volume-bar');
|
||||
this.volumeButton = this.container.querySelector('.aplayer-time button');
|
||||
this.volumeBarWrap = this.container.querySelector('.aplayer-volume-bar-wrap');
|
||||
this.loop = this.container.querySelector('.aplayer-icon-loop');
|
||||
this.order = this.container.querySelector('.aplayer-icon-order');
|
||||
this.menu = this.container.querySelector('.aplayer-icon-menu');
|
||||
this.pic = this.container.querySelector('.aplayer-pic');
|
||||
this.title = this.container.querySelector('.aplayer-title');
|
||||
this.author = this.container.querySelector('.aplayer-author');
|
||||
this.dtime = this.container.querySelector('.aplayer-dtime');
|
||||
}
|
||||
}
|
||||
|
||||
export default Template;
|
||||
@@ -0,0 +1,89 @@
|
||||
import utils from './utils';
|
||||
|
||||
class Timer {
|
||||
constructor (player) {
|
||||
this.player = player;
|
||||
|
||||
window.requestAnimationFrame = (() =>
|
||||
window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function (callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
)();
|
||||
|
||||
this.types = ['loading', 'progress'];
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
this.types.map((item) => {
|
||||
this[`init${item}Checker`]();
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
initprogressChecker () {
|
||||
this.progressChecker = setInterval(() => {
|
||||
if (this.enableprogressChecker) {
|
||||
this.player.bar.set('played', this.player.audio.currentTime / this.player.audio.duration, 'width');
|
||||
this.player.lrc && this.player.lrc.update();
|
||||
const currentTime = utils.secondToTime(this.player.audio.currentTime);
|
||||
if (this.player.template.ptime.innerHTML !== currentTime) {
|
||||
this.player.template.ptime.innerHTML = currentTime;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
initloadingChecker () {
|
||||
let lastPlayPos = 0;
|
||||
let currentPlayPos = 0;
|
||||
let bufferingDetected = false;
|
||||
this.loadingChecker = setInterval(() => {
|
||||
if (this.enableloadingChecker) {
|
||||
// whether the audio is buffering
|
||||
currentPlayPos = this.player.audio.currentTime;
|
||||
if (!bufferingDetected
|
||||
&& currentPlayPos === lastPlayPos
|
||||
&& !this.player.audio.paused) {
|
||||
this.player.container.classList.add('aplayer-loading');
|
||||
bufferingDetected = true;
|
||||
}
|
||||
if (bufferingDetected
|
||||
&& currentPlayPos > lastPlayPos
|
||||
&& !this.player.audio.paused) {
|
||||
this.player.container.classList.remove('aplayer-loading');
|
||||
bufferingDetected = false;
|
||||
}
|
||||
lastPlayPos = currentPlayPos;
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
enable (type) {
|
||||
this[`enable${type}Checker`] = true;
|
||||
|
||||
if (type === 'fps') {
|
||||
this.initfpsChecker();
|
||||
}
|
||||
}
|
||||
|
||||
disable (type) {
|
||||
this[`enable${type}Checker`] = false;
|
||||
}
|
||||
|
||||
destroy () {
|
||||
this.types.map((item) => {
|
||||
this[`enable${item}Checker`] = false;
|
||||
this[`${item}Checker`] && clearInterval(this[`${item}Checker`]);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Timer;
|
||||
@@ -0,0 +1,33 @@
|
||||
import utils from './utils';
|
||||
|
||||
class User {
|
||||
constructor (player) {
|
||||
this.storageName = {
|
||||
volume: 'aplayer-volume',
|
||||
};
|
||||
this.default = {
|
||||
volume: player.options.volume || 0.7,
|
||||
};
|
||||
this.data = {};
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
for (const item in this.storageName) {
|
||||
const name = this.storageName[item];
|
||||
this.data[item] = parseFloat(utils.storage.get(name) || this.default[item]);
|
||||
}
|
||||
}
|
||||
|
||||
get (key) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
set (key, value) {
|
||||
this.data[key] = value;
|
||||
utils.storage.set(this.storageName[key], value);
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
||||
@@ -0,0 +1,89 @@
|
||||
const isMobile = /mobile/i.test(window.navigator.userAgent);
|
||||
|
||||
const utils = {
|
||||
|
||||
/**
|
||||
* Parse second to time string
|
||||
*
|
||||
* @param {Number} second
|
||||
* @return {String} 00:00 or 00:00:00
|
||||
*/
|
||||
secondToTime: (second) => {
|
||||
const add0 = (num) => num < 10 ? '0' + num : '' + num;
|
||||
const hour = Math.floor(second / 3600);
|
||||
const min = Math.floor((second - hour * 3600) / 60);
|
||||
const sec = Math.floor(second - hour * 3600 - min * 60);
|
||||
return (hour > 0 ? [hour, min, sec] : [min, sec]).map(add0).join(':');
|
||||
},
|
||||
|
||||
/**
|
||||
* control play progress
|
||||
*/
|
||||
// get element's view position
|
||||
getElementViewLeft: (element) => {
|
||||
let actualLeft = element.offsetLeft;
|
||||
let current = element.offsetParent;
|
||||
const elementScrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
|
||||
while (current !== null) {
|
||||
actualLeft += current.offsetLeft;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (current !== null && current !== element) {
|
||||
actualLeft += current.offsetLeft;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
}
|
||||
return actualLeft - elementScrollLeft;
|
||||
},
|
||||
|
||||
getElementViewTop: (element) => {
|
||||
let actualTop = element.offsetTop;
|
||||
let current = element.offsetParent;
|
||||
let elementScrollTop = 0;
|
||||
while (current !== null) {
|
||||
actualTop += current.offsetTop;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
elementScrollTop = document.body.scrollTop + document.documentElement.scrollTop;
|
||||
return actualTop - elementScrollTop;
|
||||
},
|
||||
|
||||
isMobile: isMobile,
|
||||
|
||||
storage: {
|
||||
set: (key, value) => {
|
||||
localStorage.setItem(key, value);
|
||||
},
|
||||
|
||||
get: (key) => localStorage.getItem(key)
|
||||
},
|
||||
|
||||
nameMap: {
|
||||
dragStart: isMobile ? 'touchstart' : 'mousedown',
|
||||
dragMove: isMobile ? 'touchmove' : 'mousemove',
|
||||
dragEnd: isMobile ? 'touchend' : 'mouseup'
|
||||
},
|
||||
|
||||
/**
|
||||
* get random order, using Fisher–Yates shuffle
|
||||
*/
|
||||
randomOrder: (length = this.options.audio.length) => {
|
||||
function shuffle (arr) {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
const randomIndex = Math.floor(Math.random() * (i + 1));
|
||||
const itemAtIndex = arr[randomIndex];
|
||||
arr[randomIndex] = arr[i];
|
||||
arr[i] = itemAtIndex;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
return shuffle([...Array(length)].map(function (item, i) {
|
||||
return i;
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
export default utils;
|
||||
@@ -0,0 +1,3 @@
|
||||
{{each lyrics}}
|
||||
<p{{ if $index === 0 }} class="aplayer-lrc-current"{{ /if }}>{{$value[1]}}</p>
|
||||
{{/each}}
|
||||
@@ -0,0 +1,62 @@
|
||||
<div class="aplayer-pic"{{ if cover }} style="background-image: url("{{ cover }}");"{{ /if }}>
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</div>
|
||||
<div class="aplayer-info">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title"></span>
|
||||
<span class="aplayer-author"></span>
|
||||
</div>
|
||||
<div class="aplayer-lrc">
|
||||
<div class="aplayer-lrc-contents" style="transform: translateY(0); -webkit-transform: translateY(0);"></div>
|
||||
</div>
|
||||
<div class="aplayer-controller">
|
||||
<div class="aplayer-bar-wrap">
|
||||
<div class="aplayer-bar">
|
||||
<div class="aplayer-loaded" style="width: 0"></div>
|
||||
<div class="aplayer-played" style="width: 0; background: {{ options.theme }};">
|
||||
<span class="aplayer-thumb" style="background: {{ options.theme }};">
|
||||
<span class="aplayer-loading-icon">{{@ icons.loading }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-time">
|
||||
<span class="aplayer-time-inner">
|
||||
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||
</span>
|
||||
<div class="aplayer-volume-wrap">
|
||||
<button type="button" class="aplayer-icon aplayer-icon-volume-down">
|
||||
{{@ icons.volumeDown }}
|
||||
</button>
|
||||
<div class="aplayer-volume-bar-wrap">
|
||||
<div class="aplayer-volume-bar">
|
||||
<div class="aplayer-volume" style="height: 80%; background: {{ options.theme }};"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ if options.audio.length > 1 }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
{{ /if }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-loop">
|
||||
{{ if options.loop === 'one' }}{{@ icons.loopOne }}{{ else if options.loop === 'all' }}{{@ icons.loopAll }}{{ else if options.loop === 'none' }}{{@ icons.loopNone }}{{ /if }}
|
||||
</button>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-menu">
|
||||
{{@ icons.menu }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
<ol>
|
||||
{{each options.audio}}
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: {{ options.theme }};"></span>
|
||||
<span class="aplayer-list-index">{{ $index + 1 }}</span>
|
||||
<span class="aplayer-list-title">{{ $value.name }}</span>
|
||||
<span class="aplayer-list-author">{{ $value.artist }}</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ol>
|
||||
</div>
|
||||
@@ -1,61 +0,0 @@
|
||||
var webpack = require('webpack');
|
||||
var path = require('path');
|
||||
var autoprefixer = require('autoprefixer');
|
||||
|
||||
var ROOT_PATH = path.resolve(__dirname);
|
||||
var APP_PATH = path.resolve(ROOT_PATH, 'src');
|
||||
var BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
|
||||
|
||||
module.exports = {
|
||||
devtool: 'source-map',
|
||||
|
||||
entry: './src/APlayer.js',
|
||||
|
||||
output: {
|
||||
path: BUILD_PATH,
|
||||
filename: 'APlayer.min.js',
|
||||
library: 'APlayer',
|
||||
libraryTarget: 'umd',
|
||||
umdNamedDefine: true
|
||||
},
|
||||
|
||||
devServer: {
|
||||
publicPath: "/dist/",
|
||||
},
|
||||
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel',
|
||||
include: APP_PATH,
|
||||
query: {
|
||||
presets: ['es2015']
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: ['style', 'css', 'postcss', 'sass'],
|
||||
include: APP_PATH
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: 'url?limit=40000'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false
|
||||
}
|
||||
})
|
||||
],
|
||||
|
||||
postcss: [
|
||||
autoprefixer({
|
||||
browsers: ['last 15 versions', '> 1%', 'ie 8', 'ie 7']
|
||||
})
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,123 @@
|
||||
/* eslint-disable no-undef */
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const GitRevisionPlugin = require('git-revision-webpack-plugin');
|
||||
const gitRevisionPlugin = new GitRevisionPlugin();
|
||||
|
||||
module.exports = {
|
||||
|
||||
devtool: 'cheap-module-source-map',
|
||||
|
||||
entry: {
|
||||
'APlayer': './src/js/index.js'
|
||||
},
|
||||
|
||||
output: {
|
||||
path: path.resolve(__dirname, '..', 'dist'),
|
||||
filename: '[name].js',
|
||||
library: '[name]',
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: 'default',
|
||||
umdNamedDefine: true,
|
||||
publicPath: '/'
|
||||
},
|
||||
|
||||
resolve: {
|
||||
modules: ['node_modules'],
|
||||
extensions: ['.js', '.scss']
|
||||
},
|
||||
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
enforce: 'pre',
|
||||
loader: require.resolve('eslint-loader'),
|
||||
include: path.resolve(__dirname, '../src/js'),
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
cacheDirectory: true,
|
||||
presets: ['env']
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
require.resolve('style-loader'),
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
config: {
|
||||
path: path.join(__dirname, 'postcss.config.js')
|
||||
}
|
||||
}
|
||||
},
|
||||
require.resolve('sass-loader')
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
'limit': 40000
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.svg$/,
|
||||
loader: 'svg-inline-loader'
|
||||
},
|
||||
{
|
||||
test: /\.art$/,
|
||||
loader: 'art-template-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
devServer: {
|
||||
compress: true,
|
||||
contentBase: path.resolve(__dirname, '..', 'demo'),
|
||||
clientLogLevel: 'none',
|
||||
quiet: false,
|
||||
open: true,
|
||||
historyApiFallback: {
|
||||
disableDotRule: true
|
||||
},
|
||||
watchOptions: {
|
||||
ignored: /node_modules/
|
||||
}
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
APLAYER_VERSION: `"${require('../package.json').version}"`,
|
||||
GIT_HASH: JSON.stringify(gitRevisionPlugin.version())
|
||||
})
|
||||
],
|
||||
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty'
|
||||
},
|
||||
|
||||
performance: {
|
||||
hints: false
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
'autoprefixer': {}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,125 @@
|
||||
/* eslint-disable no-undef */
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const GitRevisionPlugin = require('git-revision-webpack-plugin');
|
||||
const gitRevisionPlugin = new GitRevisionPlugin();
|
||||
|
||||
module.exports = {
|
||||
|
||||
bail: true,
|
||||
|
||||
devtool: 'source-map',
|
||||
|
||||
entry: {
|
||||
'APlayer': './src/js/index.js'
|
||||
},
|
||||
|
||||
output: {
|
||||
path: path.resolve(__dirname, '..', 'dist'),
|
||||
filename: '[name].min.js',
|
||||
library: '[name]',
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: 'default',
|
||||
umdNamedDefine: true,
|
||||
publicPath: '/'
|
||||
},
|
||||
|
||||
resolve: {
|
||||
modules: ['node_modules'],
|
||||
extensions: ['.js', '.scss']
|
||||
},
|
||||
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
enforce: 'pre',
|
||||
loader: require.resolve('eslint-loader'),
|
||||
include: path.resolve(__dirname, '../src/js'),
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [
|
||||
require.resolve('template-string-optimize-loader'),
|
||||
{
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
compact: true,
|
||||
presets: ['env']
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: require.resolve('style-loader'),
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
minimize: true,
|
||||
sourceMap: true
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
config: {
|
||||
path: path.join(__dirname, 'postcss.config.js')
|
||||
}
|
||||
}
|
||||
},
|
||||
require.resolve('sass-loader')
|
||||
]
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
'limit': 40000
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.svg$/,
|
||||
loader: 'svg-inline-loader'
|
||||
},
|
||||
{
|
||||
test: /\.art$/,
|
||||
loader: 'art-template-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
APLAYER_VERSION: `"${require('../package.json').version}"`,
|
||||
GIT_HASH: JSON.stringify(gitRevisionPlugin.version())
|
||||
}),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
ascii_only: true
|
||||
},
|
||||
sourceMap: true
|
||||
}),
|
||||
new ExtractTextPlugin({
|
||||
filename: '[name].min.css'
|
||||
})
|
||||
],
|
||||
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
}
|
||||
|
||||
};
|
||||