18 Commits
Author SHA1 Message Date
DIYgod 097fd27caa update console version 2016-10-14 10:36:02 +08:00
DIYgod 5ce630df04 Optimize sorting algorithm for random mode, fix: #77 2016-10-14 10:26:50 +08:00
DIYgod c1c83d3c96 optimize the style of aplayer with lrc 2016-10-11 11:24:03 +08:00
DIYgod 89992c84c9 fix aplayer-bar width 2016-10-11 10:02:15 +08:00
Wenjie Fan 58a53e324c Merge pull request #76 from argvil19/display-date
display hh:mm:ss format when audio is over an hour long
2016-10-10 20:41:15 -05:00
Argenis Villasmil 02058ad17f display hh:mm:ss format when audio is over an hour long 2016-10-10 21:01:30 -04:00
DIYgod d7365d9546 Make music title and lrc selectable; click list to play next song in mobile: close #69 2016-09-30 11:13:35 +08:00
DIYgod 1386beaa27 Fix UMD bug 2016-09-26 01:50:13 +08:00
DIYgod 62d146a9dc Scrollbar style, close #72 2016-09-20 12:12:21 +08:00
DIYgod fa0017c55d random mode: from first music; play list: click to jump 2016-09-19 11:38:24 +08:00
DIYgod 9459d76b4b New option: mode, listmaxhight 2016-09-19 10:34:12 +08:00
DIYgod f7e91c04d3 fix bug in showlrc: 2 2016-09-09 01:46:23 +08:00
DIYgod 655d03bdb1 Add related projects: APlayer for WordPress 2016-09-01 01:33:09 +08:00
DIYgod 4621a74691 fix getting lrc repeatedly 2016-08-28 00:20:50 +08:00
DIYgod f91eba1aba New showlrc type: 3, get lrc from lrc file or API 2016-08-28 00:12:38 +08:00
DIYgod 210a9bbec0 Add console; Remove init function; Simplify this space; Update dev dependencies 2016-08-27 18:17:49 +08:00
DIYgod 7a45bd0cdf Update devDependencies; Add gitter to README 2016-08-18 18:44:08 +08:00
DIYgod 61f0d66b5b Fix a typo 2016-07-20 14:52:14 +08:00
11 changed files with 568 additions and 205 deletions
+23 -7
View File
@@ -5,14 +5,13 @@
[![devDependency Status](https://img.shields.io/david/dev/DIYgod/aplayer.svg?style=flat-square)](https://david-dm.org/DIYgod/APlayer#info=devDependencies)
[![npm](https://img.shields.io/npm/dt/aplayer.svg?style=flat-square)](https://www.npmjs.com/package/aplayer)
[![Travis](https://img.shields.io/travis/DIYgod/APlayer.svg?style=flat-square)](https://travis-ci.org/DIYgod/APlayer)
[![gitter](https://img.shields.io/gitter/room/DIYgod/APlayer.svg?style=flat-square)](https://gitter.im/diygod233/aplayer)
[![%e2%9d%a4](https://img.shields.io/badge/made%20with-%e2%9d%a4-ff69b4.svg?style=flat-square)](https://www.anotherhome.net/)
> Wow, such a beautiful html5 music player
## Introduction
UI 参考网易云音乐外链播放器
[Demo](http://aplayer.js.org)
Screenshot
@@ -42,7 +41,6 @@ $ npm install aplayer --save
```JS
var ap = new APlayer(option);
ap.init();
```
#### Options
@@ -55,13 +53,14 @@ var option = {
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
loop: true, // Optional, loop play music, default: true
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'metadata' in Desktop, 'none' in mobile
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
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
}
}
@@ -69,13 +68,18 @@ var option = {
#### API
+ `ap.init()`
+ `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
@@ -152,6 +156,17 @@ HTML:
</div>
```
#### LRC in lrc file or API:
```js
{
showlrc: 3,
music: {
lrc: 'path/to/music.lrc'
}
}
```
### With playlist
Show multiple music.
@@ -200,6 +215,7 @@ $ npm run build
- [163music-APlayer-you-get-docker](https://github.com/YUX-IO/163music-APlayer-you-get-docker)
- [Hermit-X(APlayer for WordPress)](https://github.com/liwanglin12/Hermit-X)
## LICENSE
+13 -12
View File
File diff suppressed because one or more lines are too long
@@ -0,0 +1,43 @@
[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]最高の思い出を…(那一段最美好的回忆…)
+51
View File
@@ -0,0 +1,51 @@
[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!!
+91
View File
@@ -0,0 +1,91 @@
[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-)
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -7
View File
@@ -1,11 +1,11 @@
{
"name": "aplayer",
"version": "1.5.0",
"version": "1.5.6",
"description": "Wow, such a beautiful html5 music player",
"main": "dist/APlayer.min.js",
"scripts": {
"test": "webpack",
"start": "webpack-dev-server --hot --progress --inline"
"start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
},
"repository": {
"type": "git",
@@ -23,18 +23,18 @@
},
"homepage": "https://github.com/DIYgod/APlayer#readme",
"devDependencies": {
"autoprefixer": "^6.3.7",
"autoprefixer": "^6.4.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"css-loader": "^0.23.1",
"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": "^0.9.1",
"postcss-loader": "^0.13.0",
"sass-loader": "^4.0.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.9.0"
"webpack-dev-server": "^1.14.1"
}
}
+270 -143
View File
@@ -1,3 +1,5 @@
console.log("\n %c APlayer 1.5.6 %c http://aplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
require('./APlayer.scss');
let instances = [];
@@ -10,20 +12,23 @@ class APlayer {
* @constructor
*/
constructor(option) {
this.svg = {
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'],
'loop': ['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'],
'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 34 32', 'M16 0c-8.837 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 29.5c-7.456 0-13.5-6.044-13.5-13.5s6.044-13.5 13.5-13.5 13.5 6.044 13.5 13.5-6.044 13.5-13.5 13.5zM15.606 12.578h-3.856v-1.563h1.207c0.429 0 0.839-0.076 1.219-0.225 0.386-0.148 0.715-0.353 0.987-0.612 0.272-0.263 0.495-0.578 0.659-0.952 0.171-0.369 0.253-0.781 0.253-1.227h1.675v16h-2.144v-11.422z'],
'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="${this.svg[type][0]}" width="100%">
<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="${this.svg[type][1]}" id="aplayer-${type}"></path>
<path class="aplayer-fill" d="${svg[type][1]}" id="aplayer-${type}"></path>
</svg>
`;
};
@@ -42,7 +47,7 @@ class APlayer {
mutex: true,
showlrc: 0,
theme: '#b7daff',
loop: true
mode: 'circulation'
};
for (let defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
@@ -55,13 +60,13 @@ class APlayer {
this.option = option;
this.audios = [];
this.loop = option.loop;
this.mode = option.mode;
/**
* Parse second to 00:00 format
* Parse second to 00:00 format. 00:00:00 if audio is over an hour long.
*
* @param {Number} second
* @return {String} 00:00 format
* @return {String} 00:00 format. 00:00:00 if over an hour long.
*/
this.secondToTime = (second) => {
const add0 = (num) => {
@@ -69,47 +74,20 @@ class APlayer {
};
const min = parseInt(second / 60);
const sec = parseInt(second - min * 60);
return add0(min) + ':' + add0(sec);
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);
};
/**
* Parse lrc, suppose multiple time tag
*
* @param {Array} arr - Format:
* [mm:ss.xx]lyric
* [mm:ss.xxx]lyric
* [mm:ss.xx][mm:ss.xx][mm:ss.xx]lyric
*
* @return {Array} [[[time, text], [time, text], [time, text], ...], [[time, text], [time, text], [time, text], ...], ...]
*/
this.parseLrc = (arr) => {
let lrcs = [];
for (let k = 0; k < arr.length; k++) {
const lyric = arr[k].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]);
lrcs.push(lrc);
// 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);
}
return lrcs;
};
}
this.lrcs = [];
/**
* Update progress bar, including loading progress bar and play progress bar
@@ -121,7 +99,7 @@ class APlayer {
this.updateBar = (type, percentage, direction) => {
percentage = percentage > 0 ? percentage : 0;
percentage = percentage < 1 ? percentage : 1;
this[type + 'Bar'].style[direction] = percentage * 100 + '%';
bar[type + 'Bar'].style[direction] = percentage * 100 + '%';
};
/**
@@ -134,8 +112,8 @@ class APlayer {
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 * 20}px)`;
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 20}px)`;
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');
}
@@ -144,53 +122,32 @@ class APlayer {
};
// define APlayer events
this.eventTypes = ['play', 'pause', 'canplay', 'playing', 'ended', 'error'];
const eventTypes = ['play', 'pause', 'canplay', 'playing', 'ended', 'error'];
this.event = {};
for (let i = 0; i < this.eventTypes.length; i++) {
this.event[this.eventTypes[i]] = [];
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]();
}
}
}
};
/**
* AutoLink initialization function
*/
init() {
this.element = this.option.element;
this.multiple = this.playIndex > -1;
this.music = this.multiple ? this.option.music[this.playIndex] : this.option.music;
let i;
// parser lrc
if (this.option.showlrc) {
let lrcs = [];
if (this.option.showlrc === 1) {
if (this.multiple) {
for (i = 0; i < this.option.music.length; i++) {
lrcs.push(this.option.music[i].lrc);
}
}
else {
lrcs.push(this.option.music.lrc);
}
}
else if (this.option.showlrc === 2 || this.option.showlrc === true) {
for (i = 0; i < this.element.getElementsByClassName('aplayer-lrc-content').length; i++) {
lrcs.push(this.element.getElementsByClassName('aplayer-lrc-content')[i].innerHTML);
}
}
this.lrcs = this.parseLrc(lrcs);
}
// 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 = `
@@ -223,7 +180,7 @@ class APlayer {
- <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">`
<button class="aplayer-icon aplayer-icon-volume-down" ${this.isMobile ? 'style="display: none;"' : ''}>`
+ this.getSVG('volume-down')
+ ` </button>
<div class="aplayer-volume-bar-wrap">
@@ -232,8 +189,8 @@ class APlayer {
</div>
</div>
</div>
<button class="aplayer-icon aplayer-icon-loop${(this.loop ? `` : ` aplayer-noloop`)}">`
+ this.getSVG('loop')
<button class="aplayer-icon aplayer-icon-mode">`
+ this.getSVG(this.mode)
+ ` </button>
${(this.multiple ? `<button class="aplayer-icon aplayer-icon-menu">`
+ this.getSVG('menu')
@@ -243,9 +200,9 @@ class APlayer {
</div>`;
if (this.multiple) {
eleHTML += `
<div class="aplayer-list">
<div class="aplayer-list" ${this.option.listmaxheight ? `style="max-height: ${this.option.listmaxheight}` : ``}">
<ol>`;
for (i = 0; i < this.option.music.length; i++) {
for (let i = 0; i < this.option.music.length; i++) {
eleHTML += `
<li>
<span class="aplayer-list-cur" style="background: ${this.option.theme};"></span>
@@ -260,9 +217,9 @@ class APlayer {
}
this.element.innerHTML = eleHTML;
// hide loop button in arrow container
// hide mode button in arrow container
if (this.element.offsetWidth < 300) {
this.element.getElementsByClassName('aplayer-icon-loop')[0].style.display = 'none';
this.element.getElementsByClassName('aplayer-icon-mode')[0].style.display = 'none';
}
this.ptime = this.element.getElementsByClassName('aplayer-ptime')[0];
@@ -271,8 +228,8 @@ class APlayer {
this.element.getElementsByClassName('aplayer-time')[0].classList.add('aplayer-time-narrow');
}
// fix the width of aplayer bar
this.bar = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
this.bar.style.marginRight = this.element.getElementsByClassName('aplayer-time')[0].offsetWidth + 5 + 'px';
let bar = {};
bar.barWrap = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
// switch to narrow style
if (this.option.narrow) {
@@ -298,12 +255,7 @@ class APlayer {
const musicIndex = parseInt(listItem[i].getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
if (musicIndex !== this.playIndex) {
this.setMusic(musicIndex);
if (this.isMobile) {
this.pause();
}
else {
this.play();
}
this.play();
}
else {
this.toggle();
@@ -313,34 +265,34 @@ class APlayer {
}
// control play progress
this.playedBar = this.element.getElementsByClassName('aplayer-played')[0];
this.loadedBar = this.element.getElementsByClassName('aplayer-loaded')[0];
this.thumb = this.element.getElementsByClassName('aplayer-thumb')[0];
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;
this.bar.addEventListener('click', (event) => {
bar.barWrap.addEventListener('click', (event) => {
const e = event || window.event;
barWidth = this.bar.clientWidth;
const percentage = (e.clientX - getElementViewLeft(this.bar)) / barWidth;
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(this.playedBar.style.width) / 100 * this.audio.duration;
this.audio.currentTime = parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration;
});
this.thumb.addEventListener('mouseover', () => {
this.thumb.style.background = this.option.theme;
thumb.addEventListener('mouseover', () => {
thumb.style.background = this.option.theme;
});
this.thumb.addEventListener('mouseout', () => {
this.thumb.style.background = '#fff';
thumb.addEventListener('mouseout', () => {
thumb.style.background = '#fff';
});
const thumbMove = (event) => {
const e = event || window.event;
let percentage = (e.clientX - getElementViewLeft(this.bar)) / barWidth;
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(this.playedBar.style.width) / 100 * this.audio.duration);
this.updateLrc(parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration);
}
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(percentage * this.audio.duration);
};
@@ -348,7 +300,7 @@ class APlayer {
const thumbUp = () => {
document.removeEventListener('mouseup', thumbUp);
document.removeEventListener('mousemove', thumbMove);
this.audio.currentTime = parseFloat(this.playedBar.style.width) / 100 * this.audio.duration;
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) {
@@ -359,15 +311,15 @@ class APlayer {
}, 100);
};
this.thumb.addEventListener('mousedown', () => {
barWidth = this.bar.clientWidth;
thumb.addEventListener('mousedown', () => {
barWidth = bar.barWrap.clientWidth;
clearInterval(this.playedTime);
document.addEventListener('mousemove', thumbMove);
document.addEventListener('mouseup', thumbUp);
});
// control volume
this.volumeBar = this.element.getElementsByClassName('aplayer-volume')[0];
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;
@@ -425,19 +377,33 @@ class APlayer {
return actualTop - elementScrollTop;
}
// loop control
const loopEle = this.element.getElementsByClassName('aplayer-icon-loop')[0];
loopEle.addEventListener('click', () => {
if (this.loop) {
loopEle.classList.add('aplayer-noloop');
this.loop = false;
this.audio.loop = this.multiple ? false : this.loop;
// 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 {
loopEle.classList.remove('aplayer-noloop');
this.loop = true;
this.audio.loop = this.multiple ? false : this.loop;
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
@@ -454,7 +420,12 @@ class APlayer {
});
}
this.setMusic(0);
if (this.mode === 'random') {
this.setMusic(this.randomOrder[0]);
}
else {
this.setMusic(0);
}
instances.push(this);
}
@@ -489,16 +460,15 @@ class APlayer {
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;
if (this.option.preload) {
this.audio.preload = this.option.preload;
}
else {
this.audio.preload = this.isMobile ? 'none' : 'metadata';
}
this.audio.preload = this.option.preload ? this.option.preload : 'auto';
// show audio time: the metadata has loaded or changed
this.audio.addEventListener('durationchange', () => {
@@ -534,23 +504,36 @@ class APlayer {
return;
}
if (this.audio.currentTime !== 0) {
if (this.playIndex < this.option.music.length - 1) {
this.setMusic(++this.playIndex);
if (this.mode === 'random') {
this.setMusic(this.nextRandomNum());
}
else if (this.loop) {
this.setMusic(0);
else if (this.mode === 'single') {
this.setMusic(this.playIndex);
}
else if (!this.loop) {
this.ended = true;
this.pause();
this.trigger('ended');
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.loop) {
if (this.mode === 'order') {
this.ended = true;
this.pause();
this.trigger('ended');
@@ -562,7 +545,7 @@ class APlayer {
this.audio.volume = parseInt(this.element.getElementsByClassName('aplayer-volume')[0].style.height) / 100;
// loop
this.audio.loop = this.multiple ? false : this.loop;
this.audio.loop = !(this.multiple || this.mode === 'order');
if (this.multiple) {
this.audios[indexMusic] = this.audio;
@@ -574,9 +557,103 @@ class APlayer {
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) {
this.lrc = this.multiple ? this.lrcs[indexMusic] : this.lrcs[0];
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++) {
@@ -709,6 +786,56 @@ class APlayer {
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;
}
}
}
export {APlayer};
module.exports = APlayer;
+66 -33
View File
@@ -1,6 +1,6 @@
$aplayer-height: 66px;
$lrc-height: 40px;
$aplayer-height-lrc: $aplayer-height + $lrc-height;
$lrc-height: 30px;
$aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
.aplayer-narrow {
width: $aplayer-height;
@@ -13,16 +13,32 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
&.aplayer-narrow {
width: $aplayer-height-lrc;
}
&.aplayer .aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
&.aplayer {
.aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
}
.aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
}
.aplayer-lrc {
display: block;
}
.aplayer-info {
padding: 10px 7px 0 7px;
}
}
&.aplayer .aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
}
&.aplayer .aplayer-lrc {
display: block;
}
.aplayer-list {
&.aplayer {
.aplayer-info {
border-bottom: 1px solid #e9e9e9;
}
}
}
@@ -133,6 +149,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: 13px;
user-select: text;
cursor: default;
padding-bottom: 2px;
.aplayer-title {
font-size: 14px;
@@ -146,11 +165,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-controller {
position: relative;
display: flex;
.aplayer-bar-wrap {
margin: 0 140px 0 5px;
margin: 0 0 0 5px;
padding: 4px 0;
cursor: pointer !important;
flex: 1;
.aplayer-bar {
position: relative;
@@ -192,12 +213,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
}
.aplayer-time {
position: absolute;
position: relative;
right: 0;
bottom: -3px;
bottom: 3px;
height: 17px;
color: #999;
font-size: 11px;
padding-left: 7px;
.aplayer-time-inner {
vertical-align: middle;
@@ -211,19 +233,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
fill: #666;
}
&.aplayer-icon-loop {
&.aplayer-icon-mode {
margin-right: 4px;
}
&.aplayer-noloop {
.aplayer-fill {
fill: #ddd;
}
&:hover {
.aplayer-fill {
fill: #bbb;
}
}
}
&:hover {
.aplayer-fill {
@@ -233,7 +245,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
}
&.aplayer-time-narrow {
.aplayer-icon-loop {
.aplayer-icon-mode {
display: none;
}
@@ -290,7 +302,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
background: #fff;
text-align: center;
overflow: hidden;
margin: -10px 0 10px;
margin: -10px 0 7px;
&:before {
position: absolute;
@@ -316,17 +328,17 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
width: 100%;
height: 33%;
content: ' ';
background: -moz-linear-gradient(bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
background: -webkit-linear-gradient(bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
background: linear-gradient(to top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 );
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 100%);
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ccffffff',GradientType=0 );
}
p {
font-size: 12px;
color: #666;
line-height: 20px !important;
height: 20px !important;
line-height: 16px !important;
height: 16px !important;
padding: 0 !important;
margin: 0 !important;
transition: all 0.5s ease-out;
@@ -341,17 +353,34 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-lrc-contents {
width: 100%;
transition: all 0.5s ease-out;
user-select: text;
cursor: default;
}
}
.aplayer-list {
overflow: auto;
transition: all 0.5s ease;
will-change: height;
&.aplayer-list-hide {
height: 0 !important;
}
&::-webkit-scrollbar{
width: 5px;
}
&::-webkit-scrollbar-track{
background-color: #f9f9f9;
}
&::-webkit-scrollbar-thumb{
border-radius: 3px;
background-color: #eee;
}
&::-webkit-scrollbar-thumb:hover{
background-color: #ccc;
}
ol {
list-style-type: none;
margin: 0;
@@ -368,6 +397,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
transition: all 0.2s ease;
overflow: hidden;
&:first-child {
border-top: none;
}
&:hover {
background: #efefef;
}
+1
View File
@@ -14,6 +14,7 @@ module.exports = {
output: {
path: BUILD_PATH,
filename: 'APlayer.min.js',
library: 'APlayer',
libraryTarget: 'umd',
umdNamedDefine: true
},