Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc31d7d9c7 | ||
|
|
af84efb05c | ||
|
|
55039bbc3b | ||
|
|
c53e9abd1c | ||
|
|
b98b466da7 | ||
|
|
49e8743da9 | ||
|
|
c5c6bfd001 | ||
|
|
483bb11507 | ||
|
|
398c8be87a | ||
|
|
1d6ceb833b | ||
|
|
a5dd690e36 | ||
|
|
b1aa4b60a2 | ||
|
|
5bfde99880 | ||
|
|
4552dd093a | ||
|
|
a002a4b180 | ||
|
|
20e2bd3e3d | ||
|
|
9c983b0833 | ||
|
|
95ee708ab1 | ||
|
|
a4bdc5345b | ||
|
|
7afe441da1 | ||
|
|
5c9456b650 | ||
|
|
4af7cab5e7 | ||
|
|
6c9dcdbbd6 | ||
|
|
6b06032c16 | ||
|
|
ddcf4612c2 | ||
|
|
72d569e08b | ||
|
|
a952bd7d33 | ||
|
|
b02e98f757 | ||
|
|
42a673d3ef | ||
|
|
07a9ae9925 | ||
|
|
bede0645ea | ||
|
|
52388dd4c1 | ||
|
|
6c343db1dd | ||
|
|
4600381784 | ||
|
|
97165f07cc | ||
|
|
9864458475 | ||
|
|
454019fea0 | ||
|
|
10d49c275a | ||
|
|
cf44440907 | ||
|
|
1dc058c0c7 | ||
|
|
738613fffe | ||
|
|
c3f74ddfe8 | ||
|
|
ba7692984a | ||
|
|
e10528397f |
@@ -50,7 +50,7 @@ Using APlayer on your project? [Let me know!](https://github.com/MoePlayer/APlay
|
||||
- [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/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
@@ -58,38 +58,21 @@ Using APlayer on your project? [Let me know!](https://github.com/MoePlayer/APlay
|
||||
|
||||
- [APlayer-Controler](https://github.com/Mashiro-Sorata/APlayer-Controler): controling tool
|
||||
- [MetingJS](https://github.com/metowolf/MetingJS): work with Meting music API
|
||||
- Feel free to submit yours in [`Let me know!`](https://github.com/MoePlayer/APlayer/issues/79)
|
||||
|
||||
## Who use APlayer?
|
||||
|
||||
- [bilibili](https://www.bilibili.com/): 国内知名的视频弹幕网站
|
||||
- [浙江大学CC98论坛](https://zh.wikipedia.org/wiki/CC98%E8%AE%BA%E5%9D%9B): 浙江大学校网内规模最大的论坛,中国各大学中较活跃的BBS之一
|
||||
- [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
|
||||
- [Opus](http://www.opusopus.co/): An artist-exploration data visualization application
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [歌词千寻](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
|
||||
- Feel free to submit yours in [`Let me know!`](https://github.com/MoePlayer/APlayer/issues/79)
|
||||
|
||||
## Current Premium Sponsors
|
||||
|
||||
@@ -112,6 +95,26 @@ 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>
|
||||
|
||||
## 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
|
||||
|
||||
## Author
|
||||
|
||||
**APlayer** © [DIYgod](https://github.com/DIYgod), Released under the [MIT](./LICENSE) License.<br>
|
||||
|
||||
+80
-9
@@ -2,7 +2,7 @@ const ap1 = new APlayer({
|
||||
element: document.getElementById('player1'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
lrc: false,
|
||||
lrcType: false,
|
||||
mutex: true,
|
||||
preload: 'metadata',
|
||||
audio: [{
|
||||
@@ -39,7 +39,7 @@ const ap2 = new APlayer({
|
||||
element: document.getElementById('player2'),
|
||||
mini: true,
|
||||
autoplay: false,
|
||||
lrc: false,
|
||||
lrcType: false,
|
||||
mutex: true,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
@@ -55,7 +55,7 @@ const ap3 = new APlayer({
|
||||
element: document.getElementById('player3'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
mutex: true,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
@@ -71,7 +71,7 @@ const ap4 = new APlayer({
|
||||
element: document.getElementById('player4'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
lrc: false,
|
||||
lrcType: false,
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
order: 'random',
|
||||
@@ -96,6 +96,13 @@ const ap4 = new APlayer({
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc',
|
||||
theme: '#505d6b'
|
||||
}, {
|
||||
name: '光るなら(HLS)',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hls/hikarunara.m3u8',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
theme: '#ebd0c2',
|
||||
type: 'hls'
|
||||
}]
|
||||
});
|
||||
|
||||
@@ -103,9 +110,9 @@ const ap5 = new APlayer({
|
||||
element: document.getElementById('player5'),
|
||||
mini: false,
|
||||
autoplay: false,
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
theme: '#e9e9e9',
|
||||
listFolded: false,
|
||||
listMaxHeight: '80px',
|
||||
audio: [{
|
||||
@@ -114,20 +121,84 @@ const ap5 = new APlayer({
|
||||
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',
|
||||
theme: '#ebd0c2'
|
||||
}, {
|
||||
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',
|
||||
theme: '#46718b'
|
||||
}, {
|
||||
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',
|
||||
theme: '#505d6b'
|
||||
}]
|
||||
});
|
||||
const colorThief = new ColorThief();
|
||||
const setTheme = (index) => {
|
||||
if (!ap5.list.audios[index].theme) {
|
||||
colorThief.getColorAsync(ap5.list.audios[index].cover, function (color) {
|
||||
ap5.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
|
||||
});
|
||||
}
|
||||
};
|
||||
setTheme(ap5.list.index);
|
||||
ap5.on('listswitch', (data) => {
|
||||
setTheme(data.index);
|
||||
});
|
||||
|
||||
const ap6 = new APlayer({
|
||||
element: document.getElementById('player6'),
|
||||
mutex: true,
|
||||
audio: [{
|
||||
name: '光るなら(HLS)',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hls/hikarunara.m3u8',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
theme: '#ebd0c2',
|
||||
type: 'hls'
|
||||
}]
|
||||
});
|
||||
const ap7 = new APlayer({
|
||||
element: document.getElementById('player7'),
|
||||
mutex: true,
|
||||
audio: [{
|
||||
name: '光るなら(HLS)',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hls/hikarunara.m3u8',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
theme: '#ebd0c2',
|
||||
type: 'customHls',
|
||||
}],
|
||||
customAudioType: {
|
||||
'customHls': function (audioElement, audio, player) {
|
||||
if (Hls.isSupported()) {
|
||||
const hls = new Hls();
|
||||
hls.loadSource(audio.url);
|
||||
hls.attachMedia(audioElement);
|
||||
}
|
||||
else if (audioElement.canPlayType('application/x-mpegURL') || audioElement.canPlayType('application/vnd.apple.mpegURL')) {
|
||||
audioElement.src = audio.url;
|
||||
}
|
||||
else {
|
||||
player.notice('Error: HLS is not supported.');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const ap8 = new APlayer({
|
||||
element: document.getElementById('player8'),
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
order: 'random',
|
||||
lrcType: 3,
|
||||
fixed: true,
|
||||
});
|
||||
$.ajax({
|
||||
url: 'https://api.i-meto.com/meting/api?server=netease&type=playlist&id=35798529',
|
||||
success: function (list) {
|
||||
ap8.list.add(JSON.parse(list));
|
||||
}
|
||||
});
|
||||
+15
-2
@@ -12,7 +12,7 @@
|
||||
max-width: 32rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 50px;
|
||||
margin-bottom: 150px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 54px;
|
||||
@@ -43,7 +43,10 @@
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
<script src="APlayer.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vconsole/dist/vconsole.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js"></script>
|
||||
<script src="APlayer.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/color-thief-don@2.0.2/src/color-thief.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@@ -90,7 +93,17 @@
|
||||
<div id="player5" class="aplayer"></div>
|
||||
<h3>Narrow</h3>
|
||||
<div id="player2" class="aplayer"></div>
|
||||
<h3>HLS</h3>
|
||||
<div id="player6" class="aplayer"></div>
|
||||
<div id="player7" class="aplayer"></div>
|
||||
<div id="player8" class="aplayer"></div>
|
||||
</div>
|
||||
<script>
|
||||
if (/mobile/i.test(window.navigator.userAgent)) {
|
||||
new VConsole();
|
||||
}
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
|
||||
<script src="demo.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Vendored
+2
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+215
-40
@@ -67,6 +67,7 @@ const ap = new APlayer(options);
|
||||
Name | Default | Description
|
||||
----|-------|----
|
||||
container | document.querySelector('.aplayer') | player container
|
||||
fixed | false | enable fixed mode, [see more details](https://aplayer.js.org/#/home?id=fixed-mode)
|
||||
mini | false | enable mini mode, [see more details](https://aplayer.js.org/#/home?id=mini-mode)
|
||||
autoplay | false | audio autoplay
|
||||
theme | '#b7daff' | main color
|
||||
@@ -81,10 +82,13 @@ audio.url | - | audio url
|
||||
audio.cover | - | audio cover
|
||||
audio.lrc | - | [see more details](https://aplayer.js.org/#/home?id=lrc)
|
||||
audio.theme | - | main color when switching to this audio, it has priority over the above theme
|
||||
audio.type | 'auto' | values: 'auto', 'hls', 'normal' or other custom type, [see more details](https://aplayer.js.org/#/home?id=mse-support)
|
||||
customAudioType | - | [see more details](https://aplayer.js.org/#/home?id=mse-support)
|
||||
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)
|
||||
lrcType | 0 | [see more details](https://aplayer.js.org/#/home?id=lrc)
|
||||
listFolded | false | indicate whether list should folded at first
|
||||
listMaxHeight | - | list max height
|
||||
storageName | 'aplayer-setting' | localStorage key that store player setting
|
||||
|
||||
For example:
|
||||
|
||||
@@ -105,7 +109,7 @@ const ap = new APlayer({
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -135,7 +139,7 @@ const ap = new APlayer({
|
||||
|
||||
+ `ap.pause()`: pause audio
|
||||
|
||||
+ `ap.seek(time: number)`: seek to specified time
|
||||
+ `ap.seek(time: number)`: seek to specified time, the unit of time is second
|
||||
|
||||
```js
|
||||
ap.seek(100);
|
||||
@@ -145,41 +149,77 @@ const ap = new APlayer({
|
||||
|
||||
+ `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',
|
||||
theme: '#ebd0c2'
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
+ `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.theme(color: string, index: number)`: set player theme, the default of index is current audio index
|
||||
|
||||
```js
|
||||
ap.theme('#000', 0);
|
||||
```
|
||||
|
||||
+ `ap.setMode(mode: string)`: set player mode, the value of mode should be 'mini' or 'normal'
|
||||
|
||||
+ `ap.mode`: return current player mode, 'mini' or 'normal'
|
||||
|
||||
+ `ap.notice(text: string, time: number, opacity: number)`: show message, the unit of time is millisecond, the default of time is 2000, the default of opacity is 0.8, setting time to 0 can disable notice autohide.
|
||||
|
||||
```js
|
||||
ap.notice('Amazing player', 2000, 0.8);
|
||||
```
|
||||
|
||||
+ `ap.skipBack()`: skip to previous audio
|
||||
|
||||
+ `ap.skipForward()`: skip to next audio
|
||||
|
||||
+ `ap.destroy()`: destroy player
|
||||
|
||||
+ `ap.lrc`
|
||||
|
||||
+ `ap.lrc.show()`: show lrc
|
||||
|
||||
+ `ap.lrc.hide()`: hide lrc
|
||||
|
||||
+ `ap.lrc.toggle()`: toggle lrc between show and hide
|
||||
|
||||
+ `ap.list`
|
||||
|
||||
+ `ap.list.show()`: show list
|
||||
|
||||
+ `ap.list.hide()`: hide list
|
||||
|
||||
+ `ap.list.toggle()`: toggle list between show and hide
|
||||
|
||||
+ `ap.list.add(audios: array | object)`: add new audios to the list
|
||||
|
||||
```js
|
||||
ap.list.add([{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
lrc: 'lrc.lrc',
|
||||
theme: '#ebd0c2'
|
||||
}]);
|
||||
```
|
||||
|
||||
+ `ap.list.remove(index: number)`: remove an audio from the list
|
||||
|
||||
```js
|
||||
ap.list.remove(1);
|
||||
```
|
||||
|
||||
+ `ap.list.switch()`: switch to an audio in the list
|
||||
|
||||
```js
|
||||
ap.list.switch(1);
|
||||
```
|
||||
|
||||
+ `ap.list.clear()`: remove all audios from the list
|
||||
|
||||
+ `ap.audio`: native audio
|
||||
|
||||
+ `ap.audio.currentTime`: returns the current playback position
|
||||
@@ -200,7 +240,7 @@ ap.on('ended', function () {
|
||||
});
|
||||
```
|
||||
|
||||
Video events
|
||||
Audio events
|
||||
|
||||
- abort
|
||||
- canplay
|
||||
@@ -228,14 +268,21 @@ Video events
|
||||
|
||||
Player events
|
||||
|
||||
- switchaudio
|
||||
- addaudio
|
||||
- removeaudio
|
||||
- listshow
|
||||
- listhide
|
||||
- listadd
|
||||
- listremove
|
||||
- listswitch
|
||||
- listclear
|
||||
- noticeshow
|
||||
- noticehide
|
||||
- destroy
|
||||
- lrcshow
|
||||
- lrchide
|
||||
|
||||
## 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.
|
||||
We have three ways to pass LRC to APlayer, indicate the way to pass LRC by option `lrcType`, 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>
|
||||
@@ -248,7 +295,7 @@ The first way, put LRC to a LRC file, LRC file will be loaded when this audio st
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
@@ -266,7 +313,7 @@ The second way, put LRC to a JS string.
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 1,
|
||||
lrcType: 1,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
@@ -303,7 +350,7 @@ The third way, put LRC to HTML.
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 2,
|
||||
lrcType: 2,
|
||||
audio: [[
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -350,7 +397,7 @@ const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -372,10 +419,33 @@ const ap = new APlayer({
|
||||
});
|
||||
```
|
||||
|
||||
## Fixed mode
|
||||
|
||||
APlayer can be fixed to page bottom via fixed mode, fixed mode is a very different mode, enjoy it!
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer9"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
fixed: true,
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
## Mini mode
|
||||
|
||||
If you don't have enough space for normal player, mini mode might be your choice.
|
||||
|
||||
Please note that mini mode is conflicted with fixed mode.
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer6"><button class="docute-button load">Click to load player</div>
|
||||
</div>
|
||||
@@ -393,6 +463,111 @@ const ap = new APlayer({
|
||||
});
|
||||
```
|
||||
|
||||
## MSE support
|
||||
|
||||
### HLS
|
||||
|
||||
It requires the library [hls.js](https://github.com/video-dev/hls.js) and it should be loaded before `APlayer.min.js`.
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer7"><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="hls.min.js"></script>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'HLS',
|
||||
artist: 'artist',
|
||||
url: 'url.m3u8',
|
||||
cover: 'cover.jpg',
|
||||
type: 'hls'
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// another way, use customType
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'HLS',
|
||||
artist: 'artist',
|
||||
url: 'url.m3u8',
|
||||
cover: 'cover.jpg',
|
||||
type: 'customHls'
|
||||
}],
|
||||
customAudioType: {
|
||||
'customHls': function (audioElement, audio, player) {
|
||||
if (Hls.isSupported()) {
|
||||
const hls = new Hls();
|
||||
hls.loadSource(audio.url);
|
||||
hls.attachMedia(audioElement);
|
||||
}
|
||||
else if (audioElement.canPlayType('application/x-mpegURL') || audioElement.canPlayType('application/vnd.apple.mpegURL')) {
|
||||
audioElement.src = audio.url;
|
||||
}
|
||||
else {
|
||||
player.notice('Error: HLS is not supported.');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Self-adapting theme according to cover
|
||||
|
||||
It requires the library [color-thief](https://github.com/lokesh/color-thief/blob/master/src/color-thief.js).
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer8"><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>
|
||||
<script src="color-thief.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
theme: '#e9e9e9',
|
||||
audio: [{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg'
|
||||
}, {
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg'
|
||||
}]
|
||||
});
|
||||
|
||||
const colorThief = new ColorThief();
|
||||
const setTheme = (index) => {
|
||||
if (!ap.list.audios[index].theme) {
|
||||
colorThief.getColorAsync(ap.list.audios[index].cover, function (color) {
|
||||
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
|
||||
});
|
||||
}
|
||||
};
|
||||
setTheme(ap.list.index);
|
||||
ap.on('listswitch', (data) => {
|
||||
setTheme(data.index);
|
||||
});
|
||||
```
|
||||
|
||||
## CDN
|
||||
|
||||
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
|
||||
@@ -403,4 +578,4 @@ const ap = new APlayer({
|
||||
|
||||
### Why can't player autoplay in some mobile browsers?
|
||||
|
||||
Most mobile browsers forbid video autoplay, you wont be able to achieve it without hacks.
|
||||
Most mobile browsers forbid audio autoplay, you wont be able to achieve it without hacks.
|
||||
+131
-6
@@ -56,6 +56,7 @@ function player () {
|
||||
context.event.on('landing:updated', function () {
|
||||
console.log('landing:updated');
|
||||
clearPlayer();
|
||||
aplayer0();
|
||||
aplayer1();
|
||||
});
|
||||
context.event.on('content:updated', function () {
|
||||
@@ -72,8 +73,8 @@ function player () {
|
||||
|
||||
function clearPlayer () {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (window['ap' + (i + 1)]) {
|
||||
window['ap' + (i + 1)].destroy();
|
||||
if (window['ap' + i]) {
|
||||
window['ap' + i].destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +83,7 @@ function aplayer1 () {
|
||||
window.ap1 = new APlayer({
|
||||
container: document.getElementById('aplayer1'),
|
||||
theme: '#F57F17',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
@@ -108,6 +109,36 @@ function aplayer1 () {
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer0 () {
|
||||
window.ap0 = new APlayer({
|
||||
container: document.getElementById('aplayer0'),
|
||||
fixed: true,
|
||||
lrcType: 3,
|
||||
audio: [{
|
||||
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',
|
||||
theme: '#505d6b'
|
||||
}, {
|
||||
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',
|
||||
theme: '#46718b'
|
||||
}, {
|
||||
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',
|
||||
theme: '#ebd0c2'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer2 () {
|
||||
window.ap2 = new APlayer({
|
||||
container: document.getElementById('aplayer2'),
|
||||
@@ -133,7 +164,7 @@ function aplayer3 () {
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
@@ -162,7 +193,7 @@ function aplayer3 () {
|
||||
function aplayer4 () {
|
||||
window.ap4 = new APlayer({
|
||||
container: document.getElementById('aplayer4'),
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
@@ -177,7 +208,7 @@ function aplayer4 () {
|
||||
function aplayer5 () {
|
||||
window.ap5 = new APlayer({
|
||||
container: document.getElementById('aplayer5'),
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
@@ -215,4 +246,98 @@ function aplayer6 () {
|
||||
theme: '#ebd0c2'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer7 () {
|
||||
window.ap7 = new APlayer({
|
||||
container: document.getElementById('aplayer7'),
|
||||
audio: [{
|
||||
name: '光るなら(HLS)',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hls/hikarunara.m3u8',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
theme: '#ebd0c2',
|
||||
type: 'hls'
|
||||
}, {
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
theme: '#ebd0c2'
|
||||
}, {
|
||||
name: 'トリカゴ',
|
||||
artist: 'XX:me',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
|
||||
theme: '#46718b'
|
||||
}, {
|
||||
name: '前前前世',
|
||||
artist: 'RADWIMPS',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
theme: '#505d6b'
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer8 () {
|
||||
window.ap8 = new APlayer({
|
||||
container: document.getElementById('aplayer8'),
|
||||
theme: '#e9e9e9',
|
||||
audio: [{
|
||||
name: '光るなら',
|
||||
artist: 'Goose house',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
|
||||
}, {
|
||||
name: 'トリカゴ',
|
||||
artist: 'XX:me',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
|
||||
}, {
|
||||
name: '前前前世',
|
||||
artist: 'RADWIMPS',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
|
||||
}]
|
||||
});
|
||||
|
||||
const colorThief = new ColorThief();
|
||||
window.ap8.on('switchaudio', function (index) {
|
||||
if (!window.ap8.options.audio[index].theme) {
|
||||
colorThief.getColorAsync(window.ap8.options.audio[index].cover, function (color) {
|
||||
window.ap8.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function aplayer9 () {
|
||||
window.ap9 = new APlayer({
|
||||
container: document.getElementById('aplayer9'),
|
||||
fixed: true,
|
||||
lrcType: 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',
|
||||
theme: '#ebd0c2'
|
||||
}, {
|
||||
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',
|
||||
theme: '#46718b'
|
||||
}, {
|
||||
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',
|
||||
theme: '#505d6b'
|
||||
}]
|
||||
});
|
||||
}
|
||||
+6
-5
@@ -27,7 +27,7 @@ Let's make APlayer better, feel free to submit yours in [`Let me know!`](https:/
|
||||
- [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/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
@@ -38,12 +38,13 @@ Let's make APlayer better, feel free to submit yours in [`Let me know!`](https:/
|
||||
|
||||
## Who use APlayer?
|
||||
|
||||
- [bilibili](https://www.bilibili.com/): 国内知名的视频弹幕网站
|
||||
- [浙江大学CC98论坛](https://zh.wikipedia.org/wiki/CC98%E8%AE%BA%E5%9D%9B): 浙江大学校网内规模最大的论坛,中国各大学中较活跃的BBS之一
|
||||
- [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
|
||||
- [Opus](http://www.opusopus.co/): An artist-exploration data visualization application
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 每日更新的LRC歌词网站
|
||||
- [iSearch](http://i.oppsu.cn): 一个提供 iTunes 搜索,试听,高清专辑封面获取,查看最新音乐动态等综合性平台
|
||||
- [LRC歌词编辑器](https://github.com/MoeFE/Lyric): 一款非常实用的在线LRC歌词编辑器
|
||||
- [Аэростатика](https://aerostatica.ru/)
|
||||
+7
-2
@@ -16,8 +16,10 @@
|
||||
|
||||
gtag('config', 'UA-48084758-8');
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.8.0/dist/APlayer.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.8.0/dist/APlayer.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/color-thief-don@2.0.2/src/color-thief.js"></script>
|
||||
<style>
|
||||
body {
|
||||
text-rendering: auto;
|
||||
@@ -29,6 +31,9 @@
|
||||
max-width: 700px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.sidebar-toggle {
|
||||
z-index: 90;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer1"></div>
|
||||
</div>
|
||||
<div id="aplayer0"></div>
|
||||
|
||||
<div class="landing-buttons">
|
||||
<a class="landing-button" target="_blank" href="https://github.com/MoePlayer/APlayer">
|
||||
|
||||
+213
-39
@@ -68,6 +68,7 @@ const ap = new APlayer(options);
|
||||
名称 | 默认值 | 描述
|
||||
----|-------|----
|
||||
container | document.querySelector('.aplayer') | 播放器容器元素
|
||||
fixed | false | 开启吸底模式, [详情](https://aplayer.js.org/#/home?id=fixed-mode)
|
||||
mini | false | 开启迷你模式, [详情](https://aplayer.js.org/#/home?id=mini-mode)
|
||||
autoplay | false | 音频自动播放
|
||||
theme | '#b7daff' | 主题色
|
||||
@@ -82,10 +83,13 @@ audio.url | - | 音频链接
|
||||
audio.cover | - | 音频封面
|
||||
audio.lrc | - | [详情](https://aplayer.js.org/#/home?id=lrc)
|
||||
audio.theme | - | 切换到此音频时的主题色,比上面的 theme 优先级高
|
||||
audio.type | 'auto' | 可选值: 'auto', 'hls', 'normal' 或其他自定义类型, [详情](https://aplayer.js.org/#/home?id=mse-support)
|
||||
customAudioType | - | 自定义类型,[详情](https://aplayer.js.org/#/home?id=mse-support)
|
||||
mutex | true | 互斥,阻止多个播放器同时播放,当前播放器播放时暂停其他播放器
|
||||
lrc | false | [详情](https://aplayer.js.org/#/home?id=lrc)
|
||||
lrcType | 0 | [详情](https://aplayer.js.org/#/home?id=lrc)
|
||||
listFolded | false | 列表默认折叠
|
||||
listMaxHeight | - | 列表最大高度
|
||||
storageName | 'aplayer-setting' | 存储播放器设置的 localStorage key
|
||||
|
||||
例如:
|
||||
|
||||
@@ -106,7 +110,7 @@ const ap = new APlayer({
|
||||
mutex: true,
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -136,7 +140,7 @@ const ap = new APlayer({
|
||||
|
||||
+ `ap.pause()`: 暂停音频
|
||||
|
||||
+ `ap.seek(time: number)`: 跳转到特定时间
|
||||
+ `ap.seek(time: number)`: 跳转到特定时间,时间的单位为秒
|
||||
|
||||
```js
|
||||
ap.seek(100);
|
||||
@@ -145,33 +149,6 @@ const ap = new APlayer({
|
||||
+ `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',
|
||||
theme: '#ebd0c2'
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
+ `ap.removeAudio(index: number)`: 从列表删除音频
|
||||
|
||||
```js
|
||||
ap.removeAudio(1);
|
||||
```
|
||||
|
||||
+ `ap.volume(percentage: number, nostorage: boolean)`: 设置音频音量
|
||||
|
||||
@@ -179,9 +156,72 @@ const ap = new APlayer({
|
||||
ap.volume(0.1, true);
|
||||
```
|
||||
|
||||
+ `ap.theme(color: string, index: number)`: 设置播放器主题色, index 默认为当前音频的 index
|
||||
|
||||
```js
|
||||
ap.theme('#000', 0);
|
||||
```
|
||||
|
||||
+ `ap.setMode(mode: string)`: 设置播放器模式,mode 取值应为 'mini' 或 'normal'
|
||||
|
||||
+ `ap.mode`: 返回播放器当前模式,'mini' 或 'normal'
|
||||
|
||||
+ `ap.notice(text: string, time: number, opacity: number)`: 显示通知,时间的单位为毫秒,默认时间 2000 毫秒,默认透明度 0.8,设置时间为 0 可以取消通知自动隐藏
|
||||
|
||||
```js
|
||||
ap.notice('Amazing player', 2000, 0.8);
|
||||
```
|
||||
|
||||
+ `ap.skipBack()`: 切换到下一首音频
|
||||
|
||||
+ `ap.skipForward()`: 切换到上一首音频
|
||||
|
||||
+ `ap.destroy()`: 销毁播放器
|
||||
|
||||
+ `ap.audio`: 原生 video
|
||||
+ `ap.lrc`
|
||||
|
||||
+ `ap.lrc.show()`: 显示歌词
|
||||
|
||||
+ `ap.lrc.hide()`: 隐藏歌词
|
||||
|
||||
+ `ap.lrc.toggle()`: 显示/隐藏歌词
|
||||
|
||||
+ `ap.list`
|
||||
|
||||
+ `ap.list.show()`: 显示播放列表
|
||||
|
||||
+ `ap.list.hide()`: 隐藏播放列表
|
||||
|
||||
+ `ap.list.toggle()`: 显示/隐藏播放列表
|
||||
|
||||
+ `ap.list.add(audios: array | object)`: 添加一个或几个新音频到播放列表
|
||||
|
||||
```js
|
||||
ap.list.add([{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
lrc: 'lrc.lrc',
|
||||
theme: '#ebd0c2'
|
||||
}]);
|
||||
```
|
||||
|
||||
+ `ap.list.remove(index: number)`: 移除播放列表中的一个音频
|
||||
|
||||
```js
|
||||
ap.list.remove(1);
|
||||
```
|
||||
|
||||
+ `ap.list.switch()`: 切换到播放列表里的其他音频
|
||||
|
||||
```js
|
||||
ap.list.switch(1);
|
||||
```
|
||||
|
||||
+ `ap.list.clear()`: 清空播放列表
|
||||
|
||||
+ `ap.audio`: 原生 audio
|
||||
|
||||
+ `ap.audio.currentTime`: 返回音频当前播放时间
|
||||
|
||||
@@ -229,14 +269,21 @@ ap.on('ended', function () {
|
||||
|
||||
播放器事件
|
||||
|
||||
- switchaudio
|
||||
- addaudio
|
||||
- removeaudio
|
||||
- listshow
|
||||
- listhide
|
||||
- listadd
|
||||
- listremove
|
||||
- listswitch
|
||||
- listclear
|
||||
- noticeshow
|
||||
- noticehide
|
||||
- destroy
|
||||
- lrcshow
|
||||
- lrchide
|
||||
|
||||
## 歌词
|
||||
|
||||
我们有三种方式来给 APlayer 传递歌词,使用 `lrc` 参数指明使用哪种方式,然后把歌词放到 `audio.lrc` 参数或者 HTML 里。
|
||||
我们有三种方式来给 APlayer 传递歌词,使用 `lrcType` 参数指明使用哪种方式,然后把歌词放到 `audio.lrc` 参数或者 HTML 里。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer4"><button class="docute-button load">点击加载播放器</div>
|
||||
@@ -249,7 +296,7 @@ ap.on('ended', function () {
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
@@ -267,7 +314,7 @@ const ap = new APlayer({
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 1,
|
||||
lrcType: 1,
|
||||
audio: {
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
@@ -304,7 +351,7 @@ const ap = new APlayer({
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
lrc: 2,
|
||||
lrcType: 2,
|
||||
audio: [[
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -351,7 +398,7 @@ const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
listFolded: false,
|
||||
listMaxHeight: '90px',
|
||||
lrc: 3,
|
||||
lrcType: 3,
|
||||
audio: [
|
||||
{
|
||||
name: 'name1',
|
||||
@@ -372,11 +419,33 @@ const ap = new APlayer({
|
||||
]
|
||||
});
|
||||
```
|
||||
## 吸底模式
|
||||
|
||||
APlayer 可以通过吸底模式固定在页面底部,这种模式跟普通模式有很大不同。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer9"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('player'),
|
||||
fixed: true,
|
||||
audio: [{
|
||||
name: 'name',
|
||||
artist: 'artist',
|
||||
url: 'url.mp3',
|
||||
cover: 'cover.jpg',
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
## 迷你模式
|
||||
|
||||
如果你没有足够空间来放置正常模式的播放器,那么你可以考虑使用迷你模式。
|
||||
|
||||
请注意迷你模式与吸底模式冲突。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer6"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
@@ -394,6 +463,111 @@ const ap = new APlayer({
|
||||
});
|
||||
```
|
||||
|
||||
## MSE 支持
|
||||
|
||||
### HLS
|
||||
|
||||
需要在 `APlayer.min.js` 前面加载 [hls.js](https://github.com/video-dev/hls.js)。
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer7"><button class="docute-button load">点击加载播放器</div>
|
||||
</div>
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="APlayer.min.css">
|
||||
<div id="aplayer"></div>
|
||||
<script src="hls.min.js"></script>
|
||||
<script src="APlayer.min.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'HLS',
|
||||
artist: 'artist',
|
||||
url: 'url.m3u8',
|
||||
cover: 'cover.jpg',
|
||||
type: 'hls'
|
||||
}]
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// 另一种方式,使用 customAudioType
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
audio: [{
|
||||
name: 'HLS',
|
||||
artist: 'artist',
|
||||
url: 'url.m3u8',
|
||||
cover: 'cover.jpg',
|
||||
type: 'customHls'
|
||||
}],
|
||||
customAudioType: {
|
||||
'customHls': function (audioElement, audio, player) {
|
||||
if (Hls.isSupported()) {
|
||||
const hls = new Hls();
|
||||
hls.loadSource(audio.url);
|
||||
hls.attachMedia(audioElement);
|
||||
}
|
||||
else if (audioElement.canPlayType('application/x-mpegURL') || audioElement.canPlayType('application/vnd.apple.mpegURL')) {
|
||||
audioElement.src = audio.url;
|
||||
}
|
||||
else {
|
||||
player.notice('Error: HLS is not supported.');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 根据封面自适应主题色
|
||||
|
||||
需要额外加载 [color-thief.js](https://github.com/lokesh/color-thief/blob/master/src/color-thief.js)
|
||||
|
||||
<div class="aplayer-wrap">
|
||||
<div id="aplayer8"><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>
|
||||
<script src="color-thief.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
const ap = new APlayer({
|
||||
container: document.getElementById('aplayer'),
|
||||
theme: '#e9e9e9',
|
||||
audio: [{
|
||||
name: 'name1',
|
||||
artist: 'artist1',
|
||||
url: 'url1.mp3',
|
||||
cover: 'cover1.jpg'
|
||||
}, {
|
||||
name: 'name2',
|
||||
artist: 'artist2',
|
||||
url: 'url2.mp3',
|
||||
cover: 'cover2.jpg'
|
||||
}]
|
||||
});
|
||||
|
||||
const colorThief = new ColorThief();
|
||||
const setTheme = (index) => {
|
||||
if (!ap.list.audios[index].theme) {
|
||||
colorThief.getColorAsync(ap.list.audios[index].cover, function (color) {
|
||||
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
|
||||
});
|
||||
}
|
||||
};
|
||||
setTheme(ap.list.index);
|
||||
ap.on('listswitch', (index) => {
|
||||
setTheme(index);
|
||||
});
|
||||
```
|
||||
|
||||
## CDN
|
||||
|
||||
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
|
||||
|
||||
@@ -28,7 +28,7 @@ search: zh-Hans
|
||||
- [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/SevenOutman/vue-aplayer): Vue
|
||||
- [vue-aplayer](https://github.com/MoeFE/vue-aplayer): Vue
|
||||
- [php-aplayer](https://github.com/Daryl-L/php-aplayer): PHP
|
||||
|
||||
@@ -39,12 +39,13 @@ search: zh-Hans
|
||||
|
||||
## 谁在用 APlayer?
|
||||
|
||||
- [bilibili](https://www.bilibili.com/): 国内知名的视频弹幕网站
|
||||
- [浙江大学CC98论坛](https://zh.wikipedia.org/wiki/CC98%E8%AE%BA%E5%9D%9B): 浙江大学校网内规模最大的论坛,中国各大学中较活跃的BBS之一
|
||||
- [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
|
||||
- [Opus](http://www.opusopus.co/): An artist-exploration data visualization application
|
||||
- [站长之家](http://www.chinaz.com/15year/index.html): 针对中文站点提供资讯、技术、资源、服务
|
||||
- [Justice_Eternal吧曲谱资源站](http://lightmoon.pw): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [Justice_Eternal吧曲谱资源站(移动端)](http://jefun.top/): 一个非营利的、兴趣驱动的曲谱编辑、发布与整理解决方案
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 歌词千寻LRC歌词编辑器
|
||||
- [LLSupport](https://www.lovelivesupport.com/): This site provides a lot of information about LoveLive
|
||||
- [歌词千寻](https://www.lrcgc.com/diy): 每日更新的LRC歌词网站
|
||||
- [iSearch](http://i.oppsu.cn): 一个提供 iTunes 搜索,试听,高清专辑封面获取,查看最新音乐动态等综合性平台
|
||||
- [LRC歌词编辑器](https://github.com/MoeFE/Lyric): 一款非常实用的在线LRC歌词编辑器
|
||||
- [Аэростатика](https://aerostatica.ru/)
|
||||
+17
-18
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aplayer",
|
||||
"version": "1.8.0",
|
||||
"version": "1.10.1",
|
||||
"description": "Wow, such a beautiful html5 music player",
|
||||
"main": "dist/APlayer.min.js",
|
||||
"style": "dist/APlayer.min.css",
|
||||
@@ -31,31 +31,30 @@
|
||||
"devDependencies": {
|
||||
"art-template": "4.12.2",
|
||||
"art-template-loader": "1.4.3",
|
||||
"autoprefixer": "^7.2.5",
|
||||
"autoprefixer": "^8.1.0",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.2",
|
||||
"babel-loader": "^7.1.4",
|
||||
"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",
|
||||
"cross-env": "^5.1.4",
|
||||
"css-loader": "^0.28.10",
|
||||
"eslint": "^4.18.2",
|
||||
"eslint-loader": "^2.0.0",
|
||||
"git-revision-webpack-plugin": "^2.5.1",
|
||||
"mini-css-extract-plugin": "0.2.0",
|
||||
"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",
|
||||
"postcss-loader": "^2.1.1",
|
||||
"sass-loader": "^6.0.7",
|
||||
"style-loader": "^0.20.3",
|
||||
"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"
|
||||
"url-loader": "^1.0.1",
|
||||
"webpack": "^4.1.1",
|
||||
"webpack-cli": "2.0.12",
|
||||
"webpack-dev-server": "^3.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"balloon-css": "^0.5.0",
|
||||
"promise-polyfill": "7.1.0"
|
||||
"promise-polyfill": "7.1.0",
|
||||
"smoothscroll": "0.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M26.667 5.333h-21.333c-0 0-0.001 0-0.001 0-1.472 0-2.666 1.194-2.666 2.666 0 0 0 0.001 0 0.001v-0 16c0 0 0 0.001 0 0.001 0 1.472 1.194 2.666 2.666 2.666 0 0 0.001 0 0.001 0h21.333c0 0 0.001 0 0.001 0 1.472 0 2.666-1.194 2.666-2.666 0-0 0-0.001 0-0.001v0-16c0-0 0-0.001 0-0.001 0-1.472-1.194-2.666-2.666-2.666-0 0-0.001 0-0.001 0h0zM5.333 16h5.333v2.667h-5.333v-2.667zM18.667 24h-13.333v-2.667h13.333v2.667zM26.667 24h-5.333v-2.667h5.333v2.667zM26.667 18.667h-13.333v-2.667h13.333v2.667z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 590 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M22 16l-10.105-10.6-1.895 1.987 8.211 8.613-8.211 8.612 1.895 1.988 8.211-8.613z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 184 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
|
||||
<path d="M25.468 6.947c-0.326-0.172-0.724-0.151-1.030 0.057l-6.438 4.38v-3.553c0-0.371-0.205-0.71-0.532-0.884-0.326-0.172-0.724-0.151-1.030 0.057l-12 8.164c-0.274 0.186-0.438 0.496-0.438 0.827s0.164 0.641 0.438 0.827l12 8.168c0.169 0.115 0.365 0.174 0.562 0.174 0.16 0 0.321-0.038 0.468-0.116 0.327-0.173 0.532-0.514 0.532-0.884v-3.556l6.438 4.382c0.169 0.115 0.365 0.174 0.562 0.174 0.16 0 0.321-0.038 0.468-0.116 0.327-0.173 0.532-0.514 0.532-0.884v-16.333c0-0.371-0.205-0.71-0.532-0.884z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 585 B |
+193
-7
@@ -11,6 +11,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
line-height: initial;
|
||||
position: relative;
|
||||
|
||||
* {
|
||||
box-sizing: content-box;
|
||||
@@ -36,6 +37,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
.aplayer-info .aplayer-controller .aplayer-time .aplayer-icon.aplayer-icon-menu {
|
||||
display: inline;
|
||||
}
|
||||
.aplayer-icon-order {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-withlrc {
|
||||
@@ -62,12 +66,124 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
.aplayer-list {
|
||||
display: none;
|
||||
}
|
||||
.aplayer-pic {
|
||||
.aplayer-pic,
|
||||
.aplayer-body {
|
||||
height: $aplayer-height;
|
||||
width: $aplayer-height;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-fixed {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
z-index: 99;
|
||||
overflow: visible;
|
||||
max-width: 400px;
|
||||
box-shadow: none;
|
||||
|
||||
.aplayer-list {
|
||||
margin-bottom: 65px;
|
||||
border: 1px solid #eee;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.aplayer-body {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
z-index: 99;
|
||||
background: #fff;
|
||||
padding-right: 18px;
|
||||
transition: all 0.3s ease;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.aplayer-lrc {
|
||||
display: block;
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
z-index: 98;
|
||||
pointer-events: none;
|
||||
text-shadow: -1px -1px 0 #fff;
|
||||
|
||||
&:before,
|
||||
&:after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-info {
|
||||
transform: scaleX(1);
|
||||
transform-origin: 0 0;
|
||||
transition: all 0.3s ease;
|
||||
border-bottom: none;
|
||||
border-top: 1px solid #e9e9e9;
|
||||
|
||||
.aplayer-music {
|
||||
width: calc(100% - 105px);
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-miniswitcher {
|
||||
display: block;
|
||||
}
|
||||
|
||||
&.aplayer-narrow {
|
||||
.aplayer-info {
|
||||
display: block;
|
||||
transform: scaleX(0);
|
||||
}
|
||||
.aplayer-body {
|
||||
width: $aplayer-height !important;
|
||||
}
|
||||
|
||||
.aplayer-miniswitcher .aplayer-icon {
|
||||
transform: rotateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-icon-back,
|
||||
.aplayer-icon-play,
|
||||
.aplayer-icon-forward,
|
||||
.aplayer-icon-lrc {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.aplayer-icon-back,
|
||||
.aplayer-icon-play,
|
||||
.aplayer-icon-forward,
|
||||
.aplayer-icon-menu {
|
||||
position: absolute;
|
||||
bottom: 27px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.aplayer-icon-back {
|
||||
right: 75px;
|
||||
}
|
||||
|
||||
.aplayer-icon-play {
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
.aplayer-icon-forward {
|
||||
right: 25px;
|
||||
}
|
||||
|
||||
.aplayer-icon-menu {
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-mobile {
|
||||
.aplayer-icon-volume-down {
|
||||
display: none;
|
||||
@@ -91,6 +207,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-body {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.aplayer-icon {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
@@ -103,13 +223,31 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
padding: 0;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
display: inline;
|
||||
display: inline-block;
|
||||
|
||||
path {
|
||||
transition: all .2s ease-in-out;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-icon-order,
|
||||
.aplayer-icon-back,
|
||||
.aplayer-icon-play,
|
||||
.aplayer-icon-forward,
|
||||
.aplayer-icon-lrc {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.aplayer-icon-lrc-inactivity {
|
||||
svg {
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-icon-forward {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.aplayer-lrc-content {
|
||||
display: none;
|
||||
}
|
||||
@@ -192,6 +330,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
user-select: text;
|
||||
cursor: default;
|
||||
padding-bottom: 2px;
|
||||
height: 20px;
|
||||
|
||||
.aplayer-title {
|
||||
font-size: 14px;
|
||||
@@ -415,9 +554,14 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
opacity: 1;
|
||||
overflow: visible;
|
||||
height: initial !important;
|
||||
min-height: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
&.aplayer-lrc-hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.aplayer-lrc-contents {
|
||||
width: 100%;
|
||||
transition: all 0.5s ease-out;
|
||||
@@ -434,7 +578,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
overflow: hidden;
|
||||
|
||||
&.aplayer-list-hide {
|
||||
height: 0 !important;
|
||||
max-height: 0 !important;
|
||||
}
|
||||
|
||||
ol {
|
||||
@@ -447,10 +591,6 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
border-radius: 3px;
|
||||
background-color: #eee;
|
||||
@@ -510,6 +650,52 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-notice {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 12px;
|
||||
border-radius: 4px;
|
||||
padding: 5px 10px;
|
||||
transition: all .3s ease-in-out;
|
||||
overflow: hidden;
|
||||
color: #fff;
|
||||
pointer-events: none;
|
||||
background-color: #f4f4f5;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.aplayer-miniswitcher {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 100%;
|
||||
background: #e6e6e6;
|
||||
width: 18px;
|
||||
border-radius: 0 2px 2px 0;
|
||||
|
||||
.aplayer-icon {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
transform: rotateY(180deg);
|
||||
transition: all 0.3s ease;
|
||||
|
||||
path {
|
||||
fill: #666;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
path {
|
||||
fill: #000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes aplayer-roll {
|
||||
|
||||
+41
-37
@@ -6,16 +6,16 @@ class Controller {
|
||||
this.player = player;
|
||||
|
||||
this.initPlayButton();
|
||||
this.initList();
|
||||
this.initPlayBar();
|
||||
if (this.player.isMultiple()) {
|
||||
this.initOrderButton();
|
||||
}
|
||||
this.initOrderButton();
|
||||
this.initLoopButton();
|
||||
this.initMenuButton();
|
||||
if (!utils.isMobile) {
|
||||
this.initVolumeButton();
|
||||
}
|
||||
this.initMiniSwitcher();
|
||||
this.initSkipButton();
|
||||
this.initLrcButton();
|
||||
}
|
||||
|
||||
initPlayButton () {
|
||||
@@ -24,34 +24,14 @@ class Controller {
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
this.player.lrc && this.player.lrc.update(percentage * this.player.duration);
|
||||
this.player.template.ptime.innerHTML = utils.secondToTime(percentage * this.player.duration);
|
||||
};
|
||||
|
||||
const thumbUp = (e) => {
|
||||
@@ -61,12 +41,12 @@ class Controller {
|
||||
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.seek(this.player.bar.get('played', 'width') * this.player.duration);
|
||||
this.player.disableTimeupdate = false;
|
||||
};
|
||||
|
||||
this.player.template.barWrap.addEventListener(utils.nameMap.dragStart, () => {
|
||||
this.player.timer.disable('progress');
|
||||
this.player.disableTimeupdate = true;
|
||||
document.addEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
document.addEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
});
|
||||
@@ -87,7 +67,7 @@ class Controller {
|
||||
});
|
||||
|
||||
const thumbMove = (e) => {
|
||||
let percentage = 1 - ((e.clientY || e.changedTouches[0].clientY) - utils.getElementViewTop(this.player.template.volumeBar)) / this.player.template.volumeBar.clientHeight;
|
||||
let percentage = 1 - ((e.clientY || e.changedTouches[0].clientY) - utils.getElementViewTop(this.player.template.volumeBar, this.player.options.fixed)) / this.player.template.volumeBar.clientHeight;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.volume(percentage);
|
||||
@@ -97,7 +77,7 @@ class Controller {
|
||||
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;
|
||||
let percentage = 1 - ((e.clientY || e.changedTouches[0].clientY) - utils.getElementViewTop(this.player.template.volumeBar, this.player.options.fixed)) / this.player.template.volumeBar.clientHeight;
|
||||
percentage = Math.max(percentage, 0);
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.player.volume(percentage);
|
||||
@@ -125,7 +105,7 @@ class Controller {
|
||||
|
||||
initLoopButton () {
|
||||
this.player.template.loop.addEventListener('click', () => {
|
||||
if (this.player.isMultiple()) {
|
||||
if (this.player.list.audios.length > 1) {
|
||||
if (this.player.options.loop === 'one') {
|
||||
this.player.options.loop = 'none';
|
||||
this.player.template.loop.innerHTML = Icons.loopNone;
|
||||
@@ -153,14 +133,38 @@ class Controller {
|
||||
}
|
||||
|
||||
initMenuButton () {
|
||||
this.player.template.list.style.height = 33 * this.player.options.audio.length - 1 + 'px';
|
||||
this.player.template.listOl.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');
|
||||
this.player.list.toggle();
|
||||
});
|
||||
}
|
||||
|
||||
initMiniSwitcher () {
|
||||
this.player.template.miniSwitcher.addEventListener('click', () => {
|
||||
this.player.setMode(this.player.mode === 'mini' ? 'normal' : 'mini');
|
||||
});
|
||||
}
|
||||
|
||||
initSkipButton () {
|
||||
this.player.template.skipBackButton.addEventListener('click', () => {
|
||||
this.player.skipBack();
|
||||
});
|
||||
this.player.template.skipForwardButton.addEventListener('click', () => {
|
||||
this.player.skipForward();
|
||||
});
|
||||
this.player.template.skipPlayButton.addEventListener('click', () => {
|
||||
this.player.toggle();
|
||||
});
|
||||
}
|
||||
|
||||
initLrcButton () {
|
||||
this.player.template.lrcButton.addEventListener('click', () => {
|
||||
if (this.player.template.lrcButton.classList.contains('aplayer-icon-lrc-inactivity')) {
|
||||
this.player.template.lrcButton.classList.remove('aplayer-icon-lrc-inactivity');
|
||||
this.player.lrc && this.player.lrc.show();
|
||||
}
|
||||
else {
|
||||
this.player.template.list.classList.remove('aplayer-list-hide');
|
||||
this.player.template.lrcButton.classList.add('aplayer-icon-lrc-inactivity');
|
||||
this.player.lrc && this.player.lrc.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+6
-3
@@ -9,7 +9,10 @@ class Events {
|
||||
'timeupdate', 'volumechange', 'waiting'
|
||||
];
|
||||
this.playerEvents = [
|
||||
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
|
||||
'destroy',
|
||||
'listshow', 'listhide', 'listadd', 'listremove', 'listswitch', 'listclear',
|
||||
'noticeshow', 'noticehide',
|
||||
'lrcshow', 'lrchide',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -22,10 +25,10 @@ class Events {
|
||||
}
|
||||
}
|
||||
|
||||
trigger (name, info) {
|
||||
trigger (name, data) {
|
||||
if (this.events[name] && this.events[name].length) {
|
||||
for (let i = 0; i < this.events[name].length; i++) {
|
||||
this.events[name][i](info);
|
||||
this.events[name][i](data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ 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';
|
||||
import right from '../assets/right.svg';
|
||||
import skip from '../assets/skip.svg';
|
||||
import lrc from '../assets/lrc.svg';
|
||||
|
||||
const Icons = {
|
||||
play: play,
|
||||
@@ -24,6 +27,9 @@ const Icons = {
|
||||
loopOne: loopOne,
|
||||
loopNone: loopNone,
|
||||
loading: loading,
|
||||
right: right,
|
||||
skip: skip,
|
||||
lrc: lrc,
|
||||
};
|
||||
|
||||
export default Icons;
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@ 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;');
|
||||
console.log(`${'\n'} %c APlayer v${APLAYER_VERSION} ${GIT_HASH} %c http://aplayer.js.org ${'\n'}`, 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;');
|
||||
|
||||
export default APlayer;
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
import tplListItem from '../template/list-item.art';
|
||||
import utils from './utils';
|
||||
import smoothScroll from 'smoothscroll';
|
||||
|
||||
class List {
|
||||
constructor (player) {
|
||||
this.player = player;
|
||||
this.index = 0;
|
||||
this.audios = this.player.options.audio;
|
||||
|
||||
this.bindEvents();
|
||||
}
|
||||
|
||||
bindEvents () {
|
||||
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.index) {
|
||||
this.switch(audioIndex);
|
||||
this.player.play();
|
||||
}
|
||||
else {
|
||||
this.player.toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
show () {
|
||||
this.player.events.trigger('listshow');
|
||||
this.player.template.list.classList.remove('aplayer-list-hide');
|
||||
this.player.template.listOl.scrollTop = this.index * 33;
|
||||
}
|
||||
|
||||
hide () {
|
||||
this.player.events.trigger('listhide');
|
||||
this.player.template.list.classList.add('aplayer-list-hide');
|
||||
}
|
||||
|
||||
toggle () {
|
||||
if (!this.player.template.list.classList.contains('aplayer-list-hide')) {
|
||||
this.hide();
|
||||
}
|
||||
else {
|
||||
this.show();
|
||||
}
|
||||
}
|
||||
|
||||
add (audios) {
|
||||
this.player.events.trigger('listadd', {
|
||||
audios: audios,
|
||||
});
|
||||
|
||||
if (Object.prototype.toString.call(audios) !== '[object Array]') {
|
||||
audios = [audios];
|
||||
}
|
||||
audios.map((item) => {
|
||||
item.name = item.name || item.title || 'Audio name';
|
||||
item.artist = item.artist || item.author || 'Audio artist';
|
||||
item.cover = item.cover || item.pic;
|
||||
item.type = item.type || 'normal';
|
||||
return item;
|
||||
});
|
||||
|
||||
const wasSingle = !(this.audios.length > 1);
|
||||
const wasEmpty = this.audios.length === 0;
|
||||
|
||||
this.player.template.listOl.innerHTML += tplListItem({
|
||||
theme: this.player.options.theme,
|
||||
audio: audios,
|
||||
index: this.audios.length + 1
|
||||
});
|
||||
|
||||
this.audios = this.audios.concat(audios);
|
||||
|
||||
if (wasSingle && this.audios.length > 1) {
|
||||
this.player.container.classList.add('aplayer-withlist');
|
||||
}
|
||||
|
||||
this.player.randomOrder = utils.randomOrder(this.audios.length);
|
||||
this.player.template.listCurs = this.player.container.querySelectorAll('.aplayer-list-cur');
|
||||
|
||||
this.player.template.listCurs[this.audios.length - 1].style.backgroundColor = audios.theme || this.player.options.theme;
|
||||
|
||||
if (wasEmpty) {
|
||||
if (this.player.options.order === 'random') {
|
||||
this.switch(this.player.randomOrder[0]);
|
||||
}
|
||||
else {
|
||||
this.switch(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
remove (index) {
|
||||
this.player.events.trigger('listremove', {
|
||||
index: index,
|
||||
});
|
||||
if (this.audios[index]) {
|
||||
if (this.audios.length > 1) {
|
||||
const list = this.player.container.querySelectorAll('.aplayer-list li');
|
||||
list[index].remove();
|
||||
|
||||
this.audios.splice(index, 1);
|
||||
this.player.lrc && this.player.lrc.remove(index);
|
||||
|
||||
if (index === this.index) {
|
||||
if (this.audios[index]) {
|
||||
this.switch(index);
|
||||
}
|
||||
else {
|
||||
this.switch(index - 1);
|
||||
}
|
||||
}
|
||||
if (this.index > index) {
|
||||
this.index--;
|
||||
}
|
||||
|
||||
for (let i = index; i < list.length; i++) {
|
||||
list[i].getElementsByClassName('aplayer-list-index')[0].textContent = i;
|
||||
}
|
||||
if (this.audios.length === 1) {
|
||||
this.player.container.classList.remove('aplayer-withlist');
|
||||
}
|
||||
|
||||
this.player.template.listCurs = this.player.container.querySelectorAll('.aplayer-list-cur');
|
||||
}
|
||||
else {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (index) {
|
||||
this.player.events.trigger('listswitch', {
|
||||
index: index,
|
||||
});
|
||||
|
||||
if (typeof index !== 'undefined' && this.audios[index]) {
|
||||
this.index = index;
|
||||
|
||||
const audio = this.audios[this.index];
|
||||
|
||||
// set html
|
||||
this.player.template.pic.style.backgroundImage = audio.cover ? `url('${audio.cover}')` : '';
|
||||
this.player.theme(this.audios[this.index].theme || this.player.options.theme, this.index, false);
|
||||
this.player.template.title.innerHTML = audio.name;
|
||||
this.player.template.author.innerHTML = audio.artist ? ' - ' + audio.artist : '';
|
||||
|
||||
const light = this.player.container.getElementsByClassName('aplayer-list-light')[0];
|
||||
if (light) {
|
||||
light.classList.remove('aplayer-list-light');
|
||||
}
|
||||
this.player.container.querySelectorAll('.aplayer-list li')[this.index].classList.add('aplayer-list-light');
|
||||
|
||||
smoothScroll(this.index * 33, 500, null, this.player.template.listOl);
|
||||
|
||||
this.player.setAudio(audio);
|
||||
|
||||
this.player.lrc && this.player.lrc.switch(this.index);
|
||||
this.player.lrc && this.player.lrc.update(0);
|
||||
|
||||
// set duration time
|
||||
if (this.player.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.player.template.dtime.innerHTML = utils.secondToTime(this.player.duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear () {
|
||||
this.player.events.trigger('listclear');
|
||||
this.index = 0;
|
||||
this.player.container.classList.remove('aplayer-withlist');
|
||||
this.player.pause();
|
||||
this.audios = [];
|
||||
this.player.lrc && this.player.lrc.clear();
|
||||
this.player.audio.src = '';
|
||||
this.player.template.listOl.innerHTML = '';
|
||||
this.player.template.pic.style.backgroundImage = '';
|
||||
this.player.theme(this.player.options.theme, this.index, false);
|
||||
this.player.template.title.innerHTML = 'No audio';
|
||||
this.player.template.author.innerHTML = '';
|
||||
this.player.bar.set('loaded', 0, 'width');
|
||||
this.player.template.dtime.innerHTML = utils.secondToTime(0);
|
||||
}
|
||||
}
|
||||
|
||||
export default List;
|
||||
+35
-8
@@ -5,12 +5,30 @@ class Lrc {
|
||||
this.container = options.container;
|
||||
this.async = options.async;
|
||||
this.player = options.player;
|
||||
this.content = options.content;
|
||||
this.parsed = [];
|
||||
this.index = 0;
|
||||
this.current = [];
|
||||
}
|
||||
|
||||
show () {
|
||||
this.player.events.trigger('lrcshow');
|
||||
this.player.template.lrcWrap.classList.remove('aplayer-lrc-hide');
|
||||
}
|
||||
|
||||
hide () {
|
||||
this.player.events.trigger('lrchide');
|
||||
this.player.template.lrcWrap.classList.add('aplayer-lrc-hide');
|
||||
}
|
||||
|
||||
toggle () {
|
||||
if (this.player.template.lrcWrap.classList.contains('aplayer-lrc-hide')) {
|
||||
this.show();
|
||||
}
|
||||
else {
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
|
||||
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++) {
|
||||
@@ -28,8 +46,8 @@ class Lrc {
|
||||
switch (index) {
|
||||
if (!this.parsed[index]) {
|
||||
if (!this.async) {
|
||||
if (this.content[index]) {
|
||||
this.parsed[index] = this.parse(this.content[index]);
|
||||
if (this.player.list.audios[index].lrc) {
|
||||
this.parsed[index] = this.parse(this.player.list.audios[index].lrc);
|
||||
}
|
||||
else {
|
||||
this.parsed[index] = [['00:00', 'Not available']];
|
||||
@@ -39,15 +57,14 @@ class Lrc {
|
||||
this.parsed[index] = [['00:00', 'Loading']];
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (index === this.player.list.index && 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.player.notice(`LRC file request fails: status ${xhr.status}`);
|
||||
this.parsed[index] = [['00:00', 'Not available']];
|
||||
}
|
||||
|
||||
this.container.innerHTML = tplLrc({
|
||||
lyrics: this.parsed[index]
|
||||
});
|
||||
@@ -55,7 +72,7 @@ class Lrc {
|
||||
this.current = this.parsed[index];
|
||||
}
|
||||
};
|
||||
const apiurl = this.content[index];
|
||||
const apiurl = this.player.list.audios[index].lrc;
|
||||
xhr.open('get', apiurl, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
@@ -84,7 +101,7 @@ class Lrc {
|
||||
if (lrc_s) {
|
||||
lrc_s = lrc_s.replace(/([^\]^\n])\[/g, (match, p1) => p1 + '\n[');
|
||||
const lyric = lrc_s.split('\n');
|
||||
const lrc = [];
|
||||
let lrc = [];
|
||||
const lyricLen = lyric.length;
|
||||
for (let i = 0; i < lyricLen; i++) {
|
||||
// match lrc time
|
||||
@@ -106,6 +123,7 @@ class Lrc {
|
||||
}
|
||||
}
|
||||
// sort by time
|
||||
lrc = lrc.filter((item) => item[1]);
|
||||
lrc.sort((a, b) => a[0] - b[0]);
|
||||
return lrc;
|
||||
}
|
||||
@@ -113,6 +131,15 @@ class Lrc {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
remove (index) {
|
||||
this.parsed.splice(index, 1);
|
||||
}
|
||||
|
||||
clear () {
|
||||
this.parsed = [];
|
||||
this.container.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
export default Lrc;
|
||||
+10
-7
@@ -3,18 +3,20 @@ export default (options) => {
|
||||
// default options
|
||||
const defaultOption = {
|
||||
container: options.element || document.getElementsByClassName('aplayer')[0],
|
||||
mini: options.narrow || false,
|
||||
mini: options.narrow || options.fixed || false,
|
||||
fixed: false,
|
||||
autoplay: false,
|
||||
mutex: true,
|
||||
lrc: options.showlrc || 0,
|
||||
lrcType: options.showlrc || options.lrc || 0,
|
||||
preload: 'auto',
|
||||
theme: '#b7daff',
|
||||
loop: 'all',
|
||||
order: 'list',
|
||||
volume: 0.7,
|
||||
listFolded: false,
|
||||
listMaxHeight: options.listmaxheight,
|
||||
audio: options.music
|
||||
listFolded: options.fixed,
|
||||
listMaxHeight: options.listmaxheight || '250px',
|
||||
audio: options.music || [],
|
||||
storageName: 'aplayer-setting'
|
||||
};
|
||||
for (const defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
|
||||
@@ -27,9 +29,10 @@ export default (options) => {
|
||||
}
|
||||
|
||||
options.audio.map((item) => {
|
||||
item.name = item.name || item.title;
|
||||
item.artist = item.artist || item.author;
|
||||
item.name = item.name || item.title || 'Audio name';
|
||||
item.artist = item.artist || item.author || 'Audio artist';
|
||||
item.cover = item.cover || item.pic;
|
||||
item.type = item.type || 'normal';
|
||||
return item;
|
||||
});
|
||||
|
||||
|
||||
+251
-220
@@ -5,11 +5,12 @@ import Icons from './icons';
|
||||
import handleOption from './options';
|
||||
import Template from './template';
|
||||
import Bar from './bar';
|
||||
import User from './user';
|
||||
import Storage from './storage';
|
||||
import Lrc from './lrc';
|
||||
import Controller from './controller';
|
||||
import Timer from './timer';
|
||||
import Events from './events';
|
||||
import List from './list';
|
||||
|
||||
const instances = [];
|
||||
|
||||
@@ -24,14 +25,14 @@ class APlayer {
|
||||
constructor (options) {
|
||||
this.options = handleOption(options);
|
||||
this.container = this.options.container;
|
||||
this.playIndex = 0;
|
||||
this.paused = true;
|
||||
this.playedPromise = Promise.resolve();
|
||||
this.mode = 'normal';
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
|
||||
this.container.classList.add('aplayer');
|
||||
if (this.options.lrc) {
|
||||
if (this.options.lrcType && !this.options.fixed) {
|
||||
this.container.classList.add('aplayer-withlrc');
|
||||
}
|
||||
if (this.options.audio.length > 1) {
|
||||
@@ -44,13 +45,10 @@ class APlayer {
|
||||
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) {
|
||||
if (this.options.lrcType === 2 || this.options.lrcType === true) {
|
||||
const lrcEle = this.container.getElementsByClassName('aplayer-lrc-content');
|
||||
for (let i = 0; i < lrcEle.length; i++) {
|
||||
if (this.options.audio[i]) {
|
||||
@@ -65,30 +63,39 @@ class APlayer {
|
||||
randomOrder: this.randomOrder,
|
||||
});
|
||||
|
||||
if (this.options.fixed) {
|
||||
this.container.classList.add('aplayer-fixed');
|
||||
this.template.body.style.width = this.template.body.offsetWidth - 18 + 'px';
|
||||
}
|
||||
if (this.options.mini) {
|
||||
this.setMode('mini');
|
||||
this.template.info.style.display = 'block';
|
||||
}
|
||||
if (this.template.info.offsetWidth < 200) {
|
||||
this.template.time.classList.add('aplayer-time-narrow');
|
||||
}
|
||||
|
||||
if (this.options.lrc) {
|
||||
if (this.options.lrcType) {
|
||||
this.lrc = new Lrc({
|
||||
container: this.template.lrc,
|
||||
async: this.options.lrc === 3,
|
||||
content: this.options.audio.map((item) => item.lrc),
|
||||
async: this.options.lrcType === 3,
|
||||
player: this,
|
||||
});
|
||||
}
|
||||
this.events = new Events();
|
||||
this.user = new User(this);
|
||||
this.storage = new Storage(this);
|
||||
this.bar = new Bar(this.template);
|
||||
this.controller = new Controller(this);
|
||||
this.timer = new Timer(this);
|
||||
this.list = new List(this);
|
||||
|
||||
this.initAudio();
|
||||
this.bindEvents();
|
||||
if (this.options.order === 'random') {
|
||||
this.switchAudio(this.randomOrder[0]);
|
||||
this.list.switch(this.randomOrder[0]);
|
||||
}
|
||||
else {
|
||||
this.switchAudio(0);
|
||||
this.list.switch(0);
|
||||
}
|
||||
|
||||
// autoplay
|
||||
@@ -104,202 +111,235 @@ class APlayer {
|
||||
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.audio.addEventListener(this.events.audioEvents[i], (e) => {
|
||||
this.events.trigger(this.events.audioEvents[i], e);
|
||||
});
|
||||
}
|
||||
|
||||
this.volume(this.storage.get('volume'), true);
|
||||
}
|
||||
|
||||
bindEvents () {
|
||||
this.on('play', () => {
|
||||
if (this.paused) {
|
||||
this.play();
|
||||
this.setUIPlaying();
|
||||
}
|
||||
});
|
||||
|
||||
this.on('pause', () => {
|
||||
if (!this.paused) {
|
||||
this.pause();
|
||||
this.setUIPaused();
|
||||
}
|
||||
});
|
||||
|
||||
this.on('timeupdate', () => {
|
||||
if (!this.disableTimeupdate) {
|
||||
this.bar.set('played', this.audio.currentTime / this.duration, 'width');
|
||||
this.lrc && this.lrc.update();
|
||||
const currentTime = utils.secondToTime(this.audio.currentTime);
|
||||
if (this.template.ptime.innerHTML !== currentTime) {
|
||||
this.template.ptime.innerHTML = currentTime;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
if (this.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
this.template.dtime.innerHTML = utils.secondToTime(this.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;
|
||||
const percentage = this.audio.buffered.length ? this.audio.buffered.end(this.audio.buffered.length - 1) / this.duration : 0;
|
||||
this.bar.set('loaded', percentage, 'width');
|
||||
});
|
||||
|
||||
// audio download error: an error occurs
|
||||
let skipTime;
|
||||
this.on('error', () => {
|
||||
this.template.author.innerHTML = ` - Error happens ╥﹏╥`;
|
||||
if (this.list.audios.length > 1) {
|
||||
this.notice('An audio error has occurred, player will skip forward in 2 seconds.');
|
||||
skipTime = setTimeout(() => {
|
||||
this.skipForward();
|
||||
if (!this.paused) {
|
||||
this.play();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
else if (this.list.audios.length === 1) {
|
||||
this.notice('An audio error has occurred.');
|
||||
}
|
||||
});
|
||||
this.events.on('listswitch', () => {
|
||||
skipTime && clearTimeout(skipTime);
|
||||
});
|
||||
|
||||
// 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);
|
||||
if (this.list.index < this.list.audios.length - 1) {
|
||||
this.list.switch((this.list.index + 1) % this.list.audios.length);
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
this.list.switch((this.list.index + 1) % this.list.audios.length);
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
if (this.randomOrder.indexOf(this.playIndex) < this.randomOrder.length - 1) {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
if (this.randomOrder.indexOf(this.list.index) < this.randomOrder.length - 1) {
|
||||
this.list.switch(this.nextIndex());
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
this.list.switch(this.nextIndex());
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.options.loop === 'one') {
|
||||
this.switchAudio(this.playIndex);
|
||||
this.list.switch(this.list.index);
|
||||
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.skipForward();
|
||||
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}')`;
|
||||
setAudio (audio) {
|
||||
if (this.hls) {
|
||||
this.hls.destroy();
|
||||
this.hls = null;
|
||||
}
|
||||
let type = audio.type;
|
||||
if (this.options.customAudioType && this.options.customAudioType[type]) {
|
||||
if (Object.prototype.toString.call(this.options.customAudioType[type]) === '[object Function]') {
|
||||
this.options.customAudioType[type](this.audio, audio, this);
|
||||
}
|
||||
else {
|
||||
this.template.pic.style.backgroundImage = '';
|
||||
console.error(`Illegal customType: ${type}`);
|
||||
}
|
||||
if (this.options.audio[this.playIndex].theme) {
|
||||
this.template.pic.style.backgroundColor = this.options.audio[this.playIndex].theme;
|
||||
this.template.played.style.background = this.options.audio[this.playIndex].theme;
|
||||
this.template.thumb.style.background = this.options.audio[this.playIndex].theme;
|
||||
this.template.volume.style.background = this.options.audio[this.playIndex].theme;
|
||||
}
|
||||
else {
|
||||
if (!type || type === 'auto') {
|
||||
if (/m3u8(#|\?|$)/i.exec(audio.url)) {
|
||||
type = 'hls';
|
||||
}
|
||||
else {
|
||||
type = 'normal';
|
||||
}
|
||||
}
|
||||
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');
|
||||
if (type === 'hls') {
|
||||
if (Hls.isSupported()) {
|
||||
this.hls = new Hls();
|
||||
this.hls.loadSource(audio.url);
|
||||
this.hls.attachMedia(this.audio);
|
||||
}
|
||||
else if (this.audio.canPlayType('application/x-mpegURL') || this.audio.canPlayType('application/vnd.apple.mpegURL')) {
|
||||
this.audio.src = audio.url;
|
||||
}
|
||||
else {
|
||||
this.notice('Error: HLS is not supported.');
|
||||
}
|
||||
}
|
||||
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();
|
||||
});
|
||||
else if (type === 'normal') {
|
||||
this.audio.src = audio.url;
|
||||
}
|
||||
}
|
||||
this.seek(0);
|
||||
|
||||
this.lrc && this.lrc.switch(this.playIndex);
|
||||
if (!this.paused) {
|
||||
this.audio.play();
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
});
|
||||
theme (color = this.list.audios[this.list.index].theme || this.options.theme, index = this.list.index, isReset = true) {
|
||||
if (isReset) {
|
||||
this.list.audios[index] && (this.list.audios[index].theme = color);
|
||||
}
|
||||
this.template.listCurs[index] && (this.template.listCurs[index].style.backgroundColor = color);
|
||||
if (index === this.list.index) {
|
||||
this.template.pic.style.backgroundColor = color;
|
||||
this.template.played.style.background = color;
|
||||
this.template.thumb.style.background = color;
|
||||
this.template.volume.style.background = color;
|
||||
}
|
||||
}
|
||||
|
||||
seek (time) {
|
||||
time = Math.max(time, 0);
|
||||
if (this.audio.duration) {
|
||||
time = Math.min(time, this.audio.duration);
|
||||
}
|
||||
|
||||
time = Math.min(time, this.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.bar.set('played', time / this.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);
|
||||
}
|
||||
get duration () {
|
||||
return isNaN(this.audio.duration) ? 0 : this.audio.duration;
|
||||
}
|
||||
|
||||
const playPromise = Promise.resolve(this.audio.play()).catch((err) => {
|
||||
console.error(err);
|
||||
this.pause();
|
||||
});
|
||||
setUIPlaying () {
|
||||
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);
|
||||
this.template.skipPlayButton.innerHTML = Icons.pause;
|
||||
}
|
||||
|
||||
this.timer.enable('loading');
|
||||
this.timer.enable('progress');
|
||||
this.timer.enable('loading');
|
||||
|
||||
if (this.options.mutex) {
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
if (this !== instances[i]) {
|
||||
instances[i].pause();
|
||||
}
|
||||
if (this.options.mutex) {
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
if (this !== instances[i]) {
|
||||
instances[i].pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return playPromise;
|
||||
});
|
||||
play () {
|
||||
this.setUIPlaying();
|
||||
|
||||
const playPromise = this.audio.play();
|
||||
if (playPromise) {
|
||||
playPromise.catch((e) => {
|
||||
console.warn(e);
|
||||
if (e.name === 'NotAllowedError') {
|
||||
this.setUIPaused();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setUIPaused () {
|
||||
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.template.skipPlayButton.innerHTML = Icons.play;
|
||||
}
|
||||
|
||||
this.container.classList.remove('aplayer-loading');
|
||||
this.timer.disable('loading');
|
||||
}
|
||||
|
||||
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');
|
||||
});
|
||||
this.setUIPaused();
|
||||
this.audio.pause();
|
||||
}
|
||||
|
||||
switchVolumeIcon () {
|
||||
@@ -324,7 +364,7 @@ class APlayer {
|
||||
percentage = Math.min(percentage, 1);
|
||||
this.bar.set('volume', percentage, 'height');
|
||||
if (!nostorage) {
|
||||
this.user.set('volume', percentage);
|
||||
this.storage.set('volume', percentage);
|
||||
}
|
||||
|
||||
this.audio.volume = percentage;
|
||||
@@ -357,97 +397,19 @@ class APlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get whether multiple audio definitions are loaded
|
||||
*/
|
||||
isMultiple () {
|
||||
return this.options.audio.length > 1;
|
||||
// abandoned
|
||||
switchAudio (index) {
|
||||
this.list.switch(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
// abandoned
|
||||
addAudio (audios) {
|
||||
this.list.add(audios);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: ${newMusic[i].theme || 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.template.listOl.style.height = songListLength * 33 - 1 + 'px';
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove song from playlist
|
||||
*/
|
||||
// abandoned
|
||||
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';
|
||||
this.template.listOl.style.height = parseInt(this.template.listOl.style.height, 10) - 33 + 'px';
|
||||
}
|
||||
this.list.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,10 +424,79 @@ class APlayer {
|
||||
this.events.trigger('destroy');
|
||||
}
|
||||
|
||||
handlePlayPromise (callback) {
|
||||
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
|
||||
console.error(err);
|
||||
setMode (mode = 'normal') {
|
||||
this.mode = mode;
|
||||
if (mode === 'mini') {
|
||||
this.container.classList.add('aplayer-narrow');
|
||||
}
|
||||
else if (mode === 'normal') {
|
||||
this.container.classList.remove('aplayer-narrow');
|
||||
}
|
||||
}
|
||||
|
||||
notice (text, time = 2000, opacity = 0.8) {
|
||||
this.template.notice.innerHTML = text;
|
||||
this.template.notice.style.opacity = opacity;
|
||||
if (this.noticeTime) {
|
||||
clearTimeout(this.noticeTime);
|
||||
}
|
||||
this.events.trigger('noticeshow', {
|
||||
text: text,
|
||||
});
|
||||
if (time) {
|
||||
this.noticeTime = setTimeout(() => {
|
||||
this.template.notice.style.opacity = 0;
|
||||
this.events.trigger('noticehide');
|
||||
}, time);
|
||||
}
|
||||
}
|
||||
|
||||
prevIndex () {
|
||||
if (this.list.audios.length > 1) {
|
||||
if (this.options.order === 'list') {
|
||||
return this.list.index - 1 < 0 ? this.list.audios.length - 1 : this.list.index - 1;
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
const index = this.randomOrder.indexOf(this.list.index);
|
||||
if (index === 0) {
|
||||
return this.randomOrder[this.randomOrder.length - 1];
|
||||
}
|
||||
else {
|
||||
return this.randomOrder[index - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nextIndex () {
|
||||
if (this.list.audios.length > 1) {
|
||||
if (this.options.order === 'list') {
|
||||
return (this.list.index + 1) % this.list.audios.length;
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
const index = this.randomOrder.indexOf(this.list.index);
|
||||
if (index === this.randomOrder.length - 1) {
|
||||
return this.randomOrder[0];
|
||||
}
|
||||
else {
|
||||
return this.randomOrder[index + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
skipBack () {
|
||||
this.list.switch(this.prevIndex());
|
||||
}
|
||||
|
||||
skipForward () {
|
||||
this.list.switch(this.nextIndex());
|
||||
}
|
||||
|
||||
static get version () {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import utils from './utils';
|
||||
|
||||
class Storage {
|
||||
constructor (player) {
|
||||
this.storageName = player.options.storageName;
|
||||
|
||||
this.data = JSON.parse(utils.storage.get(this.storageName));
|
||||
if (!this.data) {
|
||||
this.data = {};
|
||||
}
|
||||
this.data.volume = this.data.volume || player.options.volume;
|
||||
}
|
||||
|
||||
get (key) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
set (key, value) {
|
||||
this.data[key] = value;
|
||||
utils.storage.set(this.storageName, JSON.stringify(this.data));
|
||||
}
|
||||
}
|
||||
|
||||
export default Storage;
|
||||
+18
-6
@@ -10,28 +10,34 @@ class Template {
|
||||
}
|
||||
|
||||
init () {
|
||||
let cover;
|
||||
if (this.options.order === 'random') {
|
||||
cover = this.options.audio[this.randomOrder[0]].cover;
|
||||
}
|
||||
else {
|
||||
cover = this.options.audio[0].cover;
|
||||
let cover = '';
|
||||
if (this.options.audio.length) {
|
||||
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,
|
||||
getObject: (obj) => obj,
|
||||
});
|
||||
|
||||
this.lrc = this.container.querySelector('.aplayer-lrc-contents');
|
||||
this.lrcWrap = this.container.querySelector('.aplayer-lrc');
|
||||
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.body = this.container.querySelector('.aplayer-body');
|
||||
this.list = this.container.querySelector('.aplayer-list');
|
||||
this.listOl = this.container.querySelector('.aplayer-list ol');
|
||||
this.listCurs = this.container.querySelectorAll('.aplayer-list-cur');
|
||||
this.played = this.container.querySelector('.aplayer-played');
|
||||
this.loaded = this.container.querySelector('.aplayer-loaded');
|
||||
this.thumb = this.container.querySelector('.aplayer-thumb');
|
||||
@@ -46,6 +52,12 @@ class Template {
|
||||
this.title = this.container.querySelector('.aplayer-title');
|
||||
this.author = this.container.querySelector('.aplayer-author');
|
||||
this.dtime = this.container.querySelector('.aplayer-dtime');
|
||||
this.notice = this.container.querySelector('.aplayer-notice');
|
||||
this.miniSwitcher = this.container.querySelector('.aplayer-miniswitcher');
|
||||
this.skipBackButton = this.container.querySelector('.aplayer-icon-back');
|
||||
this.skipForwardButton = this.container.querySelector('.aplayer-icon-forward');
|
||||
this.skipPlayButton = this.container.querySelector('.aplayer-icon-play');
|
||||
this.lrcButton = this.container.querySelector('.aplayer-icon-lrc');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-19
@@ -1,4 +1,3 @@
|
||||
import utils from './utils';
|
||||
|
||||
class Timer {
|
||||
constructor (player) {
|
||||
@@ -15,31 +14,17 @@ class Timer {
|
||||
}
|
||||
)();
|
||||
|
||||
this.types = ['loading', 'progress'];
|
||||
this.types = ['loading'];
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
this.types.map((item) => {
|
||||
this.types.forEach((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;
|
||||
@@ -78,10 +63,9 @@ class Timer {
|
||||
}
|
||||
|
||||
destroy () {
|
||||
this.types.map((item) => {
|
||||
this.types.forEach((item) => {
|
||||
this[`enable${item}Checker`] = false;
|
||||
this[`${item}Checker`] && clearInterval(this[`${item}Checker`]);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
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;
|
||||
+3
-3
@@ -39,7 +39,7 @@ const utils = {
|
||||
return actualLeft - elementScrollLeft;
|
||||
},
|
||||
|
||||
getElementViewTop: (element) => {
|
||||
getElementViewTop: (element, noScrollTop) => {
|
||||
let actualTop = element.offsetTop;
|
||||
let current = element.offsetParent;
|
||||
let elementScrollTop = 0;
|
||||
@@ -48,7 +48,7 @@ const utils = {
|
||||
current = current.offsetParent;
|
||||
}
|
||||
elementScrollTop = document.body.scrollTop + document.documentElement.scrollTop;
|
||||
return actualTop - elementScrollTop;
|
||||
return noScrollTop ? actualTop : actualTop - elementScrollTop;
|
||||
},
|
||||
|
||||
isMobile: isMobile,
|
||||
@@ -70,7 +70,7 @@ const utils = {
|
||||
/**
|
||||
* get random order, using Fisher–Yates shuffle
|
||||
*/
|
||||
randomOrder: (length = this.options.audio.length) => {
|
||||
randomOrder: (length) => {
|
||||
function shuffle (arr) {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
const randomIndex = Math.floor(Math.random() * (i + 1));
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{{each audio}}
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background-color: {{ $value.theme || theme }};"></span>
|
||||
<span class="aplayer-list-index">{{ $index + index }}</span>
|
||||
<span class="aplayer-list-title">{{ $value.name }}</span>
|
||||
<span class="aplayer-list-author">{{ $value.artist }}</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
+138
-51
@@ -1,62 +1,149 @@
|
||||
<div class="aplayer-pic" style="{{ if cover }}background-image: url("{{ cover }}");{{ /if }}background-color: {{ options.theme }};">
|
||||
<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>
|
||||
{{ if !options.fixed }}
|
||||
<div class="aplayer-body">
|
||||
<div class="aplayer-pic" style="{{ if cover }}background-image: url("{{ cover }}");{{ /if }}background-color: {{ options.theme }};">
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</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 class="aplayer-info">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title">No audio</span>
|
||||
<span class="aplayer-author"></span>
|
||||
</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 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>
|
||||
{{ 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 class="aplayer-time">
|
||||
<span class="aplayer-time-inner">
|
||||
<span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||
</span>
|
||||
<span class="aplayer-icon aplayer-icon-back">
|
||||
{{@ icons.skip }}
|
||||
</span>
|
||||
<span class="aplayer-icon aplayer-icon-play">
|
||||
{{@ icons.play }}
|
||||
</span>
|
||||
<span class="aplayer-icon aplayer-icon-forward">
|
||||
{{@ icons.skip }}
|
||||
</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>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
<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>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-lrc">
|
||||
{{@ icons.lrc }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-notice"></div>
|
||||
<div class="aplayer-miniswitcher"><button class="aplayer-icon">{{@ icons.right }}</button></div>
|
||||
</div>
|
||||
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
{{each options.audio}}
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: {{ $value.theme || 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}}
|
||||
{{ include './list-item.art' getObject({
|
||||
theme: options.theme,
|
||||
audio: options.audio,
|
||||
index: 1
|
||||
}) }}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
{{ include './list-item.art' getObject({
|
||||
theme: options.theme,
|
||||
audio: options.audio,
|
||||
index: 1
|
||||
}) }}
|
||||
</ol>
|
||||
</div>
|
||||
<div class="aplayer-body">
|
||||
<div class="aplayer-pic" style="{{ if cover }}background-image: url("{{ cover }}");{{ /if }}background-color: {{ options.theme }};">
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</div>
|
||||
<div class="aplayer-info" style="display: none;">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title">No audio</span>
|
||||
<span class="aplayer-author"></span>
|
||||
</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>
|
||||
<span class="aplayer-icon aplayer-icon-back">
|
||||
{{@ icons.skip }}
|
||||
</span>
|
||||
<span class="aplayer-icon aplayer-icon-play">
|
||||
{{@ icons.play }}
|
||||
</span>
|
||||
<span class="aplayer-icon aplayer-icon-forward">
|
||||
{{@ icons.skip }}
|
||||
</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>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
<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>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-lrc">
|
||||
{{@ icons.lrc }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-notice"></div>
|
||||
<div class="aplayer-miniswitcher"><button class="aplayer-icon">{{@ icons.right }}</button></div>
|
||||
</div>
|
||||
<div class="aplayer-lrc">
|
||||
<div class="aplayer-lrc-contents" style="transform: translateY(0); -webkit-transform: translateY(0);"></div>
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -6,6 +6,8 @@ const gitRevisionPlugin = new GitRevisionPlugin();
|
||||
|
||||
module.exports = {
|
||||
|
||||
mode: 'development',
|
||||
|
||||
devtool: 'cheap-module-source-map',
|
||||
|
||||
entry: {
|
||||
@@ -33,14 +35,14 @@ module.exports = {
|
||||
{
|
||||
test: /\.js$/,
|
||||
enforce: 'pre',
|
||||
loader: require.resolve('eslint-loader'),
|
||||
loader: 'eslint-loader',
|
||||
include: path.resolve(__dirname, '../src/js'),
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('babel-loader'),
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
cacheDirectory: true,
|
||||
presets: ['env']
|
||||
@@ -51,27 +53,27 @@ module.exports = {
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
require.resolve('style-loader'),
|
||||
'style-loader',
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
importLoaders: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
loader: 'postcss-loader',
|
||||
options: {
|
||||
config: {
|
||||
path: path.join(__dirname, 'postcss.config.js')
|
||||
}
|
||||
}
|
||||
},
|
||||
require.resolve('sass-loader')
|
||||
'sass-loader'
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: require.resolve('url-loader'),
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
'limit': 40000
|
||||
}
|
||||
@@ -102,7 +104,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
APLAYER_VERSION: `"${require('../package.json').version}"`,
|
||||
GIT_HASH: JSON.stringify(gitRevisionPlugin.version())
|
||||
|
||||
+27
-37
@@ -1,12 +1,14 @@
|
||||
/* eslint-disable no-undef */
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const GitRevisionPlugin = require('git-revision-webpack-plugin');
|
||||
const gitRevisionPlugin = new GitRevisionPlugin();
|
||||
|
||||
module.exports = {
|
||||
|
||||
mode: 'production',
|
||||
|
||||
bail: true,
|
||||
|
||||
devtool: 'source-map',
|
||||
@@ -36,15 +38,15 @@ module.exports = {
|
||||
{
|
||||
test: /\.js$/,
|
||||
enforce: 'pre',
|
||||
loader: require.resolve('eslint-loader'),
|
||||
loader: 'eslint-loader',
|
||||
include: path.resolve(__dirname, '../src/js'),
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [
|
||||
require.resolve('template-string-optimize-loader'),
|
||||
'template-string-optimize-loader',
|
||||
{
|
||||
loader: require.resolve('babel-loader'),
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
compact: true,
|
||||
presets: ['env']
|
||||
@@ -54,32 +56,30 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: require.resolve('style-loader'),
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
minimize: true,
|
||||
sourceMap: true
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
minimize: true,
|
||||
sourceMap: true
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: {
|
||||
config: {
|
||||
path: path.join(__dirname, 'postcss.config.js')
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
config: {
|
||||
path: path.join(__dirname, 'postcss.config.js')
|
||||
}
|
||||
}
|
||||
},
|
||||
require.resolve('sass-loader')
|
||||
]
|
||||
})
|
||||
}
|
||||
},
|
||||
'sass-loader',
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg)$/,
|
||||
loader: require.resolve('url-loader'),
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
'limit': 40000
|
||||
}
|
||||
@@ -100,17 +100,7 @@ module.exports = {
|
||||
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({
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '[name].min.css'
|
||||
})
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user