23 Commits
Author SHA1 Message Date
DIYgod 07a9ae9925 release v1.9.1 2018-03-14 23:58:10 +08:00
DIYgod bede0645ea remove loading when paused 2018-03-14 23:21:22 +08:00
DIYgod 52388dd4c1 changeable template.listCurs 2018-03-14 23:11:22 +08:00
DIYgod 6c343db1dd docs: fix hls demo 2018-03-14 02:32:05 +08:00
DIYgod 4600381784 release v1.9.0 2018-03-14 02:28:31 +08:00
DIYgod 97165f07cc support hls; new option: audio.type, customAudioType 2018-03-14 02:27:08 +08:00
DIYgod 9864458475 optimize error handling; remove line before current time 2018-03-14 00:59:28 +08:00
DIYgod 454019fea0 fix asynchronization conflict 2018-03-14 00:25:54 +08:00
DIYgod 10d49c275a fix inverse disableTimeupdate 2018-03-14 00:19:24 +08:00
DIYgod cf44440907 new api: notice 2018-03-14 00:02:58 +08:00
DIYgod 1dc058c0c7 new api: setMode 2018-03-13 17:37:48 +08:00
DIYgod 738613fffe option: lrc -> lrcType 2018-03-13 17:13:15 +08:00
DIYgod c3f74ddfe8 docs: self-adapting theme according to cover 2018-03-13 17:01:31 +08:00
DIYgod ba7692984a new api: theme 2018-03-13 17:01:18 +08:00
DIYgod e10528397f replace dirty checking with timeupdate 2018-03-13 11:26:29 +08:00
DIYgod 6deeacd374 release 1.8.0 2018-03-12 23:01:16 +08:00
DIYgod ed18fa77e2 fix scroll bar when folding list 2018-03-12 22:56:33 +08:00
DIYgod b5e8cd0bea audio.theme 2018-03-12 17:23:41 +08:00
DIYgod de788582f0 new API: APlayer.version 2018-03-12 15:35:13 +08:00
DIYgod 8aa8ba968d fix the css conflict between mini mode and play list 2018-03-12 15:12:56 +08:00
DIYgod f867b54094 fix clearPlayer in docs 2018-03-12 02:38:02 +08:00
DIYgod 539b71b091 fix clearPlayer in docs 2018-03-12 02:35:20 +08:00
DIYgod d437aba2f5 update js and css in docs 2018-03-12 02:33:29 +08:00
21 changed files with 782 additions and 275 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
![image](https://i.imgur.com/JDrJXCr.png)
APlayer is a lovely HTML5 music player to help people build audio easily.
APlayer is a lovely HTML5 music player.
**APlayer supports:**
+127 -72
View File
@@ -1,17 +1,17 @@
const ap1 = new APlayer({
element: document.getElementById('player1'),
mini: false,
autoplay: true,
lrc: false,
autoplay: false,
lrcType: false,
mutex: true,
theme: '#e6d0b2',
preload: 'metadata',
audio: {
name: 'Preparation',
artist: 'Hans Zimmer/Richard Harvey',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
}
audio: [{
name: '光るなら',
artist: 'Goose house',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
theme: '#ebd0c2'
}]
});
ap1.on('play', function () {
console.log('play');
@@ -39,92 +39,147 @@ const ap2 = new APlayer({
element: document.getElementById('player2'),
mini: true,
autoplay: false,
lrc: false,
lrcType: false,
mutex: true,
theme: '#e6d0b2',
audio: {
name: 'Preparation',
artist: 'Hans Zimmer/Richard Harvey',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
}
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'
}]
});
const ap3 = new APlayer({
element: document.getElementById('player3'),
mini: false,
autoplay: false,
lrc: 3,
lrcType: 3,
mutex: true,
theme: '#615754',
audio: {
name: '回レ!雪月花',
artist: '小倉唯',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
lrc: "https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc"
}
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'
}]
});
const ap4 = new APlayer({
element: document.getElementById('player4'),
mini: false,
autoplay: false,
lrc: false,
lrcType: false,
mutex: true,
theme: '#ad7a86',
order: 'random',
audio: [
{
name: 'あっちゅ~ま青春!',
artist: '七森中☆ごらく部',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
},
{
name: 'secret base~君がくれたもの~',
artist: '茅野愛衣',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
},
{
name: '回レ!雪月花',
artist: '小倉唯',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
}
]
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'
}, {
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 ap5 = new APlayer({
element: document.getElementById('player5'),
mini: false,
autoplay: false,
lrc: 3,
lrcType: 3,
mutex: true,
theme: '#ad7a86',
listFolded: true,
audio: [
{
name: 'あっちゅ~ま青春!',
artist: '七森中☆ごらく部',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.lrc'
},
{
name: 'secret base~君がくれたもの~',
artist: '茅野愛衣',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.lrc'
},
{
name: '回レ!雪月花',
artist: '小倉唯',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc'
theme: '#e9e9e9',
listFolded: false,
listMaxHeight: '80px',
audio: [{
name: '光るなら',
artist: 'Goose house',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc',
}, {
name: 'トリカゴ',
artist: 'XX:me',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/darling.lrc',
}, {
name: '前前前世',
artist: 'RADWIMPS',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.jpg',
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc',
}]
});
const colorThief = new ColorThief();
ap5.on('switchaudio', (index) => {
if (!ap5.options.audio[index].theme) {
colorThief.getColorAsync(ap5.options.audio[index].cover, function (color) {
ap5.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, 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.');
}
}
]
}
});
+6 -1
View File
@@ -43,7 +43,9 @@
font-size: 18px;
}
</style>
<script src="APlayer.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,6 +92,9 @@
<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>
<script src="demo.js"></script>
</body>
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+143 -14
View File
@@ -48,7 +48,7 @@ const ap = new APlayer({
name: 'name',
artist: 'artist',
url: 'url.mp3',
cover: 'cover.jpg',
cover: 'cover.jpg'
}]
});
```
@@ -80,8 +80,11 @@ audio.artist | - | audio artist
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
@@ -104,21 +107,23 @@ const ap = new APlayer({
mutex: true,
listFolded: false,
listMaxHeight: '90px',
lrc: 3,
lrcType: 3,
audio: [
{
name: 'name1',
artist: 'artist1',
url: 'url1.mp3',
cover: 'cover1.jpg',
lrc: 'lrc1.lrc'
lrc: 'lrc1.lrc',
theme: '#ebd0c2'
},
{
name: 'name2',
artist: 'artist2',
url: 'url2.mp3',
cover: 'cover2.jpg',
lrc: 'lrc2.lrc'
lrc: 'lrc2.lrc',
theme: '#46718b'
}
]
});
@@ -126,11 +131,13 @@ const ap = new APlayer({
## API
+ `APlayer.version`: static property, return the version of APlayer
+ `ap.play()`: play audio
+ `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);
@@ -155,7 +162,8 @@ const ap = new APlayer({
artist: 'artist',
url: 'url.mp3',
cover: 'cover.jpg',
lrc: 'lrc.lrc'
lrc: 'lrc.lrc',
theme: '#ebd0c2'
}
]);
```
@@ -172,6 +180,22 @@ const ap = new APlayer({
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.destroy()`: destroy player
+ `ap.audio`: native audio
@@ -226,10 +250,12 @@ Player events
- addaudio
- removeaudio
- destroy
- notice_show
- notice_hide
## 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>
@@ -242,7 +268,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',
@@ -260,7 +286,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',
@@ -297,7 +323,7 @@ The third way, put LRC to HTML.
```js
const ap = new APlayer({
container: document.getElementById('aplayer'),
lrc: 2,
lrcType: 2,
audio: [[
{
name: 'name1',
@@ -344,21 +370,23 @@ const ap = new APlayer({
container: document.getElementById('player'),
listFolded: false,
listMaxHeight: '90px',
lrc: 3,
lrcType: 3,
audio: [
{
name: 'name1',
artist: 'artist1',
url: 'url1.mp3',
cover: 'cover1.jpg',
lrc: 'lrc1.lrc'
lrc: 'lrc1.lrc',
theme: '#ebd0c2'
},
{
name: 'name2',
artist: 'artist2',
url: 'url2.mp3',
cover: 'cover2.jpg',
lrc: 'lrc2.lrc'
lrc: 'lrc2.lrc',
theme: '#46718b'
}
]
});
@@ -385,6 +413,107 @@ 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();
ap.on('switchaudio', (index) => {
if (!ap.options.audio[index].theme) {
colorThief.getColorAsync(ap.options.audio[index].cover, (color) => {
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
});
}
});
```
## CDN
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
+93 -19
View File
@@ -71,9 +71,9 @@ function player () {
}
function clearPlayer () {
for (let i = 1; i < 10; i++) {
if (window['dp' + (i + 1)]) {
window['dp' + (i + 1)].destroy();
for (let i = 0; i < 10; i++) {
if (window['ap' + (i + 1)]) {
window['ap' + (i + 1)].destroy();
}
}
}
@@ -82,25 +82,28 @@ function aplayer1 () {
window.ap1 = new APlayer({
container: document.getElementById('aplayer1'),
theme: '#F57F17',
lrc: 3,
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'
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'
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'
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc',
theme: '#505d6b'
}]
});
}
@@ -108,12 +111,12 @@ function aplayer1 () {
function aplayer2 () {
window.ap2 = new APlayer({
container: document.getElementById('aplayer2'),
theme: '#e6d0b2',
audio: [{
name: '光るなら',
artist: 'Goose house',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
theme: '#ebd0c2'
}]
});
}
@@ -123,7 +126,6 @@ function aplayer3 () {
container: document.getElementById('aplayer3'),
mini: false,
autoplay: false,
theme: '#FADFA3',
loop: 'all',
order: 'random',
preload: 'auto',
@@ -131,25 +133,28 @@ function aplayer3 () {
mutex: true,
listFolded: false,
listMaxHeight: '90px',
lrc: 3,
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'
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'
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'
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc',
theme: '#505d6b'
}]
});
}
@@ -157,13 +162,14 @@ function aplayer3 () {
function aplayer4 () {
window.ap4 = new APlayer({
container: document.getElementById('aplayer4'),
lrc: 3,
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"
lrc: "https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.lrc",
theme: '#ebd0c2'
}]
});
}
@@ -171,25 +177,28 @@ function aplayer4 () {
function aplayer5 () {
window.ap5 = new APlayer({
container: document.getElementById('aplayer5'),
lrc: 3,
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'
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'
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'
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yourname.lrc',
theme: '#505d6b'
}]
});
}
@@ -203,6 +212,71 @@ function aplayer6 () {
artist: 'Goose house',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3',
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg',
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);
});
}
});
}
+4 -2
View File
@@ -16,8 +16,10 @@
gtag('config', 'UA-48084758-8');
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.9.1/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.9.1/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;
+143 -14
View File
@@ -49,7 +49,7 @@ const ap = new APlayer({
name: 'name',
artist: 'artist',
url: 'url.mp3',
cover: 'cover.jpg',
cover: 'cover.jpg'
}]
});
```
@@ -81,8 +81,11 @@ audio.artist | - | 音频艺术家
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 | - | 列表最大高度
@@ -105,21 +108,23 @@ const ap = new APlayer({
mutex: true,
listFolded: false,
listMaxHeight: '90px',
lrc: 3,
lrcType: 3,
audio: [
{
name: 'name1',
artist: 'artist1',
url: 'url1.mp3',
cover: 'cover1.jpg',
lrc: 'lrc1.lrc'
lrc: 'lrc1.lrc',
theme: '#ebd0c2'
},
{
name: 'name2',
artist: 'artist2',
url: 'url2.mp3',
cover: 'cover2.jpg',
lrc: 'lrc2.lrc'
lrc: 'lrc2.lrc',
theme: '#46718b'
}
]
});
@@ -127,11 +132,13 @@ const ap = new APlayer({
## API
+ `APlayer.version`: 静态属性, 返回 APlayer 的版本号
+ `ap.play()`: 播放音频
+ `ap.pause()`: 暂停音频
+ `ap.seek(time: number)`: 跳转到特定时间
+ `ap.seek(time: number)`: 跳转到特定时间,时间的单位为秒
```js
ap.seek(100);
@@ -156,7 +163,8 @@ const ap = new APlayer({
artist: 'artist',
url: 'url.mp3',
cover: 'cover.jpg',
lrc: 'lrc.lrc'
lrc: 'lrc.lrc',
theme: '#ebd0c2'
}
]);
```
@@ -173,6 +181,22 @@ 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.destroy()`: 销毁播放器
+ `ap.audio`: 原生 video
@@ -227,10 +251,12 @@ ap.on('ended', function () {
- addaudio
- removeaudio
- destroy
- notice_show
- notice_hide
## 歌词
我们有三种方式来给 APlayer 传递歌词,使用 `lrc` 参数指明使用哪种方式,然后把歌词放到 `audio.lrc` 参数或者 HTML 里。
我们有三种方式来给 APlayer 传递歌词,使用 `lrcType` 参数指明使用哪种方式,然后把歌词放到 `audio.lrc` 参数或者 HTML 里。
<div class="aplayer-wrap">
<div id="aplayer4"><button class="docute-button load">点击加载播放器</div>
@@ -243,7 +269,7 @@ ap.on('ended', function () {
```js
const ap = new APlayer({
container: document.getElementById('aplayer'),
lrc: 3,
lrcType: 3,
audio: {
name: 'name',
artist: 'artist',
@@ -261,7 +287,7 @@ const ap = new APlayer({
```js
const ap = new APlayer({
container: document.getElementById('aplayer'),
lrc: 1,
lrcType: 1,
audio: {
name: 'name',
artist: 'artist',
@@ -298,7 +324,7 @@ const ap = new APlayer({
```js
const ap = new APlayer({
container: document.getElementById('aplayer'),
lrc: 2,
lrcType: 2,
audio: [[
{
name: 'name1',
@@ -345,21 +371,23 @@ const ap = new APlayer({
container: document.getElementById('player'),
listFolded: false,
listMaxHeight: '90px',
lrc: 3,
lrcType: 3,
audio: [
{
name: 'name1',
artist: 'artist1',
url: 'url1.mp3',
cover: 'cover1.jpg',
lrc: 'lrc1.lrc'
lrc: 'lrc1.lrc',
theme: '#ebd0c2'
},
{
name: 'name2',
artist: 'artist2',
url: 'url2.mp3',
cover: 'cover2.jpg',
lrc: 'lrc2.lrc'
lrc: 'lrc2.lrc',
theme: '#46718b'
}
]
});
@@ -386,6 +414,107 @@ 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();
ap.on('switchaudio', (index) => {
if (!ap.options.audio[index].theme) {
colorThief.getColorAsync(ap.options.audio[index].cover, (color) => {
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
});
}
});
```
## CDN
- [jsDelivr](https://www.jsdelivr.com/package/npm/aplayer)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "aplayer",
"version": "1.7.0",
"version": "1.9.1",
"description": "Wow, such a beautiful html5 music player",
"main": "dist/APlayer.min.js",
"style": "dist/APlayer.min.css",
+85 -63
View File
@@ -2,54 +2,6 @@ $aplayer-height: 66px;
$lrc-height: 30px;
$aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
.aplayer-narrow {
width: $aplayer-height;
.aplayer-info {
display: none;
}
}
.aplayer-withlrc {
&.aplayer-narrow {
width: $aplayer-height-lrc;
}
&.aplayer {
.aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
}
.aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
}
.aplayer-lrc {
display: block;
}
.aplayer-info {
padding: 10px 7px 0 7px;
}
}
}
.aplayer-withlist {
&.aplayer {
.aplayer-info {
border-bottom: 1px solid #e9e9e9;
}
.aplayer-list {
display: block;
}
.aplayer-icon-menu {
display: inline !important;
}
}
}
.aplayer {
background: #fff;
font-family: Arial, Helvetica, sans-serif;
@@ -59,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;
@@ -74,6 +27,49 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
}
}
&.aplayer-withlist {
.aplayer-info {
border-bottom: 1px solid #e9e9e9;
}
.aplayer-list {
display: block;
}
.aplayer-info .aplayer-controller .aplayer-time .aplayer-icon.aplayer-icon-menu {
display: inline;
}
}
&.aplayer-withlrc {
.aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
}
.aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
padding: 10px 7px 0 7px;
}
.aplayer-lrc {
display: block;
}
}
&.aplayer-narrow {
width: $aplayer-height;
.aplayer-info {
display: none;
}
.aplayer-list {
display: none;
}
.aplayer-pic,
.aplayer-body {
height: $aplayer-height;
width: $aplayer-height;
}
}
&.aplayer-mobile {
.aplayer-icon-volume-down {
display: none;
@@ -97,6 +93,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
}
}
.aplayer-body {
position: relative;
}
.aplayer-icon {
width: 15px;
height: 15px;
@@ -125,8 +125,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
float: left;
height: $aplayer-height;
width: $aplayer-height;
background-image: url(data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAeAAD/4QMfaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2J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4fpPydJ9T5vqfT/ABaJadMvmljKCHLjxnBDDXDPGXGJmTkcogETMshjyxlPhFGqqfVT0b9QMSy2twDnSkkdsJtoomK7cC2KoB1plKtSVfmKT4ST0qUVQ7KbQ62th3xNuJUhY46VDSewwhvqrdvXsPrTqUMZ/C82fCVJP1dhiVYvKjY9vcVqpqhxgH8tQDgHQZpMRT7EokkF+qccHyISlufX4oubddKG5shymWCvNbRwWk84jtBMgeSGRNaKOgo7eyWaNoNIPvEYqUfqUcTHVOMRIxOKscooyBxg5eSIM5T48IkY/vgJOPVBOXOIBM80aKqspaNvzap1LaRlM4noGZgOjVBC5+sqX1ejyj6aUp6vxf6tGUuac4ImwxbAkKlEzBywjHGUgermiRPLhFGYJ48Y01tDSXBg09Y2HG5+E5KSZZoUMo2AgZRkDiBLDiIBQq9n3ClcL9pf80JxSkny3k9fuqjBvcu4bYfLuDBWBh+MgoV/eMDDoMyZ4RIM0kETT8pxETPi6WmN9UKhJ+ncQTnpIUP2R1p3jZCMVOJ5igxYu2q1vmbtGwvn0JB7JRznbthOJoW8eQqHcqHU40K3nZAMFOKllJB/bHI9vuiTMU9M44o/MQkdk4tUbdsaDMUTXXNXeY6maChp5eTTNI5ClCQe6HThWN+3Rc/Bb6UtIV8SUH/NeEZ02zrhWOefdqognNKT5izzajgIbpz7gIkfzhhqs/TFk9J6b0w05+ZM+ZPl1wRay9kEUV4y+qXZGachyc8EEBKeMAnLCf8ACCCAzE5d8ZHMS64IIA7oy+HDqgggIEpYdUZJnpE84IICeScSJYwQQE8IIIID/9k=);
background-size: cover;
background-position: center;
transition: all 0.3s ease;
cursor: pointer;
@@ -437,29 +437,34 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
transition: all 0.5s ease;
will-change: height;
display: none;
overflow: hidden;
&.aplayer-list-hide {
height: 0 !important;
}
&::-webkit-scrollbar{
width: 5px;
}
&::-webkit-scrollbar-track{
background-color: #f9f9f9;
}
&::-webkit-scrollbar-thumb{
border-radius: 3px;
background-color: #eee;
}
&::-webkit-scrollbar-thumb:hover{
background-color: #ccc;
}
ol {
list-style-type: none;
margin: 0;
padding: 0;
overflow-y: auto;
&::-webkit-scrollbar {
width: 5px;
}
&::-webkit-scrollbar-track {
background-color: #f9f9f9;
}
&::-webkit-scrollbar-thumb {
border-radius: 3px;
background-color: #eee;
}
&::-webkit-scrollbar-thumb:hover {
background-color: #ccc;
}
li {
position: relative;
@@ -511,6 +516,23 @@ $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;
}
}
@keyframes aplayer-roll {
+3 -2
View File
@@ -62,11 +62,11 @@ class Controller {
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.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);
});
@@ -154,6 +154,7 @@ 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');
+1 -1
View File
@@ -9,7 +9,7 @@ class Events {
'timeupdate', 'volumechange', 'waiting'
];
this.playerEvents = [
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
'destroy', 'switchaudio', 'addaudio', 'removeaudio', 'notice_show', 'notice_hide'
];
}
+2 -2
View File
@@ -39,12 +39,12 @@ class Lrc {
this.parsed[index] = [['00:00', 'Loading']];
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (index === this.player.playIndex && 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']];
}
+2 -1
View File
@@ -6,7 +6,7 @@ export default (options) => {
mini: options.narrow || false,
autoplay: false,
mutex: true,
lrc: options.showlrc || 0,
lrcType: options.showlrc || options.lrc || 0,
preload: 'auto',
theme: '#b7daff',
loop: 'all',
@@ -30,6 +30,7 @@ export default (options) => {
item.name = item.name || item.title;
item.artist = item.artist || item.author;
item.cover = item.cover || item.pic;
item.type = item.type || 'normal';
return item;
});
+117 -19
View File
@@ -27,11 +27,12 @@ class APlayer {
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.container.classList.add('aplayer-withlrc');
}
if (this.options.audio.length > 1) {
@@ -45,12 +46,12 @@ class APlayer {
this.container.classList.add('aplayer-arrow');
}
if (this.options.mini) {
this.container.classList.add('aplayer-narrow');
this.setMode('mini');
}
// 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]) {
@@ -69,10 +70,10 @@ class APlayer {
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,
async: this.options.lrcType === 3,
content: this.options.audio.map((item) => item.lrc),
player: this,
});
@@ -104,8 +105,8 @@ 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);
});
}
@@ -121,6 +122,17 @@ class APlayer {
}
});
this.on('timeupdate', () => {
if (!this.disableTimeupdate) {
this.bar.set('played', this.audio.currentTime / this.audio.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
@@ -136,7 +148,7 @@ class APlayer {
// audio download error: an error occurs
this.on('error', () => {
this.template.author.innerHTML = ` - Error happens ╥﹏╥`;
this.notice('An audio error has occurred.');
});
// multiple audio play
@@ -188,15 +200,17 @@ class APlayer {
this.playIndex = index;
}
const audio = this.options.audio[this.playIndex];
// set html
if (this.options.audio[this.playIndex].cover) {
this.template.pic.style.backgroundImage = `url('${this.options.audio[this.playIndex].cover}')`;
if (audio.cover) {
this.template.pic.style.backgroundImage = `url('${audio.cover}')`;
}
else {
this.template.pic.style.backgroundImage = '';
}
this.template.title.innerHTML = this.options.audio[this.playIndex].name;
this.template.author.innerHTML = this.options.audio[this.playIndex].artist ? ' - ' + this.options.audio[this.playIndex].artist : '';
this.theme();
this.template.title.innerHTML = audio.name;
this.template.author.innerHTML = audio.artist ? ' - ' + audio.artist : '';
const light = this.container.getElementsByClassName('aplayer-list-light')[0];
if (light) {
light.classList.remove('aplayer-list-light');
@@ -205,7 +219,47 @@ class APlayer {
this.template.list.scrollTop = this.playIndex * 33;
this.audio.src = this.options.audio[this.playIndex].url;
// mse
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 {
console.error(`Illegal customType: ${type}`);
}
}
else {
if (!type || type === 'auto') {
if (/m3u8(#|\?|$)/i.exec(audio.url)) {
type = 'hls';
}
else {
type = 'normal';
}
}
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.');
}
}
else if (type === 'normal') {
this.audio.src = audio.url;
}
}
this.seek(0);
let playPromise;
@@ -227,6 +281,17 @@ class APlayer {
});
}
theme (color = this.options.audio[this.playIndex].theme, index = this.playIndex) {
this.options.audio[index].theme = color;
this.template.listCurs[index].style.backgroundColor = color;
if (index === this.playIndex) {
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) {
@@ -262,7 +327,6 @@ class APlayer {
});
this.timer.enable('loading');
this.timer.enable('progress');
if (this.options.mutex) {
for (let i = 0; i < instances.length; i++) {
@@ -291,8 +355,8 @@ class APlayer {
this.audio.pause();
this.container.classList.remove('aplayer-loading');
this.timer.disable('loading');
this.timer.disable('progress');
});
}
@@ -391,7 +455,7 @@ class APlayer {
for (let i = 0; i < newMusic.length; i++) {
newItemHTML += `
<li>
<span class="aplayer-list-cur" style="background: ${this.options.theme};"></span>
<span class="aplayer-list-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>
@@ -403,10 +467,11 @@ class APlayer {
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.list.style.height = this.options.audio.length * 33 - 1 + 'px';
this.template.listOl.style.height = this.options.audio.length * 33 - 1 + 'px';
this.randomOrder = utils.randomOrder(this.options.audio.length);
this.template.listCurs = this.container.querySelectorAll('.aplayer-list-cur');
}
/**
@@ -438,7 +503,10 @@ class APlayer {
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.list.style.height = this.options.audio.length * 33 - 1 + 'px';
this.template.listOl.style.height = this.options.audio.length * 33 - 1 + 'px';
this.template.listCurs = this.container.querySelectorAll('.aplayer-list-cur');
}
}
@@ -454,11 +522,41 @@ class APlayer {
this.events.trigger('destroy');
}
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('notice_show', text);
if (time) {
this.noticeTime = setTimeout(() => {
this.template.notice.style.opacity = 0;
this.events.trigger('notice_hide');
}, time);
}
}
handlePlayPromise (callback) {
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
console.error(err);
});
}
static get version () {
/* global APLAYER_VERSION */
return APLAYER_VERSION;
}
}
export default APlayer;
+2
View File
@@ -32,6 +32,7 @@ class Template {
this.button = this.container.querySelector('.aplayer-button');
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 +47,7 @@ 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');
}
}
+1 -15
View File
@@ -1,4 +1,3 @@
import utils from './utils';
class Timer {
constructor (player) {
@@ -15,7 +14,7 @@ class Timer {
}
)();
this.types = ['loading', 'progress'];
this.types = ['loading'];
this.init();
}
@@ -27,19 +26,6 @@ class Timer {
});
}
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;
+47 -44
View File
@@ -1,58 +1,61 @@
<div class="aplayer-pic"{{ if cover }} style="background-image: url("{{ cover }}");"{{ /if }}>
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
</div>
<div class="aplayer-info">
<div class="aplayer-music">
<span class="aplayer-title"></span>
<span class="aplayer-author"></span>
<div class="aplayer-body">
<div class="aplayer-pic" style="{{ if cover }}background-image: url(&quot;{{ cover }}&quot;);{{ /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"></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>
<div class="aplayer-volume-wrap">
<button type="button" class="aplayer-icon aplayer-icon-volume-down">
{{@ icons.volumeDown }}
</button>
<div class="aplayer-volume-bar-wrap">
<div class="aplayer-volume-bar">
<div class="aplayer-volume" style="height: 80%; background: {{ options.theme }};"></div>
</div>
</div>
</div>
{{ if options.audio.length > 1 }}
<button type="button" class="aplayer-icon aplayer-icon-order">
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
</button>
{{ /if }}
<button type="button" class="aplayer-icon aplayer-icon-loop">
{{ if options.loop === 'one' }}{{@ icons.loopOne }}{{ else if options.loop === 'all' }}{{@ icons.loopAll }}{{ else if options.loop === 'none' }}{{@ icons.loopNone }}{{ /if }}
</button>
<button type="button" class="aplayer-icon aplayer-icon-menu">
{{@ icons.menu }}
</button>
</div>
</div>
</div>
<div class="aplayer-notice"></div>
</div>
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
<ol>
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
{{each options.audio}}
<li>
<span class="aplayer-list-cur" style="background: {{ options.theme }};"></span>
<span class="aplayer-list-cur" style="background-color: {{ $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>