Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b0be17c70 | ||
|
|
d985b8dd8f | ||
|
|
96190c0ebf | ||
|
|
c7df64b2fd | ||
|
|
e78ac91628 | ||
|
|
9030303ad1 | ||
|
|
097fd27caa | ||
|
|
5ce630df04 | ||
|
|
c1c83d3c96 | ||
|
|
89992c84c9 | ||
|
|
58a53e324c | ||
|
|
02058ad17f | ||
|
|
d7365d9546 |
@@ -1,11 +1,11 @@
|
|||||||
# APlayer
|
# APlayer
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/aplayer)
|
[](https://www.npmjs.com/package/aplayer)
|
||||||
|
[](https://cdnjs.com/libraries/aplayer)
|
||||||
[](https://github.com/DIYgod/APlayer/blob/master/LICENSE)
|
[](https://github.com/DIYgod/APlayer/blob/master/LICENSE)
|
||||||
[](https://david-dm.org/DIYgod/APlayer#info=devDependencies)
|
[](https://david-dm.org/DIYgod/APlayer#info=devDependencies)
|
||||||
[](https://www.npmjs.com/package/aplayer)
|
[](https://www.npmjs.com/package/aplayer)
|
||||||
[](https://travis-ci.org/DIYgod/APlayer)
|
[](https://travis-ci.org/DIYgod/APlayer)
|
||||||
[](https://gitter.im/diygod233/aplayer)
|
|
||||||
[](https://www.anotherhome.net/)
|
[](https://www.anotherhome.net/)
|
||||||
|
|
||||||
> Wow, such a beautiful html5 music player
|
> Wow, such a beautiful html5 music player
|
||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
[Demo](http://aplayer.js.org)
|
[Demo](http://aplayer.js.org)
|
||||||
|
|
||||||
|
Using APlayer on your project? [Let me know!](https://github.com/DIYgod/APlayer/issues/79)
|
||||||
|
|
||||||
Screenshot
|
Screenshot
|
||||||

|

|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ var option = {
|
|||||||
mutex: true, // Optional, pause other players when this player playing
|
mutex: true, // Optional, pause other players when this player playing
|
||||||
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
|
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
|
||||||
mode: 'random', // Optional, play mode, can be `random` `single` `circulation`(loop) `order`(no loop), default: `circulation`
|
mode: 'random', // Optional, play mode, can be `random` `single` `circulation`(loop) `order`(no loop), default: `circulation`
|
||||||
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'metadata' in Desktop, 'none' in mobile
|
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
|
||||||
listmaxheight: '513px', // Optional, max height of play list
|
listmaxheight: '513px', // Optional, max height of play list
|
||||||
music: { // Required, music info, see: ###With playlist
|
music: { // Required, music info, see: ###With playlist
|
||||||
title: 'Preparation', // Required, music title
|
title: 'Preparation', // Required, music title
|
||||||
@@ -74,6 +76,12 @@ var option = {
|
|||||||
+ `ap.toggle()` // Toggle between play and pause
|
+ `ap.toggle()` // Toggle between play and pause
|
||||||
+ `ap.volume(percentage)` // Set volume
|
+ `ap.volume(percentage)` // Set volume
|
||||||
+ `ap.on(event, handler)` // Event binding
|
+ `ap.on(event, handler)` // Event binding
|
||||||
|
+ `ap.setMusic(index)` // Switch music
|
||||||
|
+ `ap.lrc` // Lrc time and text
|
||||||
|
+ `ap.playIndex` // Current playing index
|
||||||
|
+ `ap.audio` // Return native video, most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
|
||||||
|
+ `dp.audio.currentTime` // Returns the current playback position
|
||||||
|
+ Most [native api](http://www.w3schools.com/tags/ref_av_dom.asp)
|
||||||
|
|
||||||
#### Event binding
|
#### Event binding
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
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
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "aplayer",
|
"name": "aplayer",
|
||||||
"version": "1.5.3",
|
"version": "1.5.7",
|
||||||
"description": "Wow, such a beautiful html5 music player",
|
"description": "Wow, such a beautiful html5 music player",
|
||||||
"main": "dist/APlayer.min.js",
|
"main": "dist/APlayer.min.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "webpack",
|
"test": "webpack",
|
||||||
"start": "webpack-dev-server --hot --progress --inline"
|
"start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"exports-loader": "^0.6.3",
|
"exports-loader": "^0.6.3",
|
||||||
"file-loader": "^0.9.0",
|
"file-loader": "^0.9.0",
|
||||||
"node-sass": "^3.8.0",
|
"node-sass": "^3.8.0",
|
||||||
"postcss-loader": "^0.13.0",
|
"postcss-loader": "^1.0.0",
|
||||||
"sass-loader": "^4.0.0",
|
"sass-loader": "^4.0.0",
|
||||||
"style-loader": "^0.13.1",
|
"style-loader": "^0.13.1",
|
||||||
"url-loader": "^0.5.7",
|
"url-loader": "^0.5.7",
|
||||||
|
|||||||
+105
-49
@@ -1,4 +1,4 @@
|
|||||||
console.log("\n %c APlayer 1.5.3 %c http://aplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
|
console.log("\n %c APlayer 1.5.7 %c http://aplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
|
||||||
|
|
||||||
require('./APlayer.scss');
|
require('./APlayer.scss');
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class APlayer {
|
|||||||
'circulation': ['0 0 29 32', 'M25.6 9.92q1.344 0 2.272 0.928t0.928 2.272v9.28q0 1.28-0.928 2.24t-2.272 0.96h-22.4q-1.28 0-2.24-0.96t-0.96-2.24v-9.28q0-1.344 0.96-2.272t2.24-0.928h8v-3.52l6.4 5.76-6.4 5.76v-3.52h-6.72v6.72h19.84v-6.72h-4.8v-4.48h6.080z'],
|
'circulation': ['0 0 29 32', 'M25.6 9.92q1.344 0 2.272 0.928t0.928 2.272v9.28q0 1.28-0.928 2.24t-2.272 0.96h-22.4q-1.28 0-2.24-0.96t-0.96-2.24v-9.28q0-1.344 0.96-2.272t2.24-0.928h8v-3.52l6.4 5.76-6.4 5.76v-3.52h-6.72v6.72h19.84v-6.72h-4.8v-4.48h6.080z'],
|
||||||
'random': ['0 0 33 31', 'M29.867 9.356l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.219-0.5-0.5v-3.002h-4.002c-2.079 0-3.064 1.423-3.94 3.111-0.453 0.875-0.844 1.782-1.219 2.673-1.735 4.033-3.768 8.223-8.849 8.223h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.079 0 3.064-1.423 3.94-3.111 0.453-0.875 0.844-1.782 1.219-2.673 1.735-4.033 3.768-8.223 8.849-8.223h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36zM10.262 14.781c-0.907-1.892-1.907-3.783-4.268-3.783h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.783 0 4.831 1.298 6.41 3.518-0.876 1.344-1.517 2.798-2.142 4.268zM29.867 23.363l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.235-0.5-0.5v-3.002c-4.643 0-7.504 0.547-10.396-3.518 0.86-1.344 1.501-2.798 2.126-4.268 0.907 1.892 1.907 3.783 4.268 3.783h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36z'],
|
'random': ['0 0 33 31', 'M29.867 9.356l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.219-0.5-0.5v-3.002h-4.002c-2.079 0-3.064 1.423-3.94 3.111-0.453 0.875-0.844 1.782-1.219 2.673-1.735 4.033-3.768 8.223-8.849 8.223h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.079 0 3.064-1.423 3.94-3.111 0.453-0.875 0.844-1.782 1.219-2.673 1.735-4.033 3.768-8.223 8.849-8.223h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36zM10.262 14.781c-0.907-1.892-1.907-3.783-4.268-3.783h-3.502c-0.281 0-0.5-0.219-0.5-0.5v-3.002c0-0.281 0.219-0.5 0.5-0.5h3.502c2.783 0 4.831 1.298 6.41 3.518-0.876 1.344-1.517 2.798-2.142 4.268zM29.867 23.363l-5.003 5.003c-0.094 0.094-0.235 0.141-0.36 0.141-0.266 0-0.5-0.235-0.5-0.5v-3.002c-4.643 0-7.504 0.547-10.396-3.518 0.86-1.344 1.501-2.798 2.126-4.268 0.907 1.892 1.907 3.783 4.268 3.783h4.002v-3.002c0-0.281 0.219-0.5 0.5-0.5 0.141 0 0.266 0.063 0.375 0.156l4.987 4.987c0.094 0.094 0.141 0.235 0.141 0.36s-0.047 0.266-0.141 0.36z'],
|
||||||
'order': ['0 0 32 32', 'M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z'],
|
'order': ['0 0 32 32', 'M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z'],
|
||||||
'single': ['0 0 34 32', 'M16 0c-8.837 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 29.5c-7.456 0-13.5-6.044-13.5-13.5s6.044-13.5 13.5-13.5 13.5 6.044 13.5 13.5-6.044 13.5-13.5 13.5zM15.606 12.578h-3.856v-1.563h1.207c0.429 0 0.839-0.076 1.219-0.225 0.386-0.148 0.715-0.353 0.987-0.612 0.272-0.263 0.495-0.578 0.659-0.952 0.171-0.369 0.253-0.781 0.253-1.227h1.675v16h-2.144v-11.422z'],
|
'single': ['0 0 38 32', 'M2.072 21.577c0.71-0.197 1.125-0.932 0.928-1.641-0.221-0.796-0.333-1.622-0.333-2.457 0-5.049 4.108-9.158 9.158-9.158h5.428c0.056-0.922 0.221-1.816 0.482-2.667h-5.911c-3.158 0-6.128 1.23-8.361 3.463s-3.463 5.203-3.463 8.361c0 1.076 0.145 2.143 0.431 3.171 0.164 0.59 0.7 0.976 1.284 0.976 0.117 0 0.238-0.016 0.357-0.049zM21.394 25.613h-12.409v-2.362c0-0.758-0.528-1.052-1.172-0.652l-5.685 3.522c-0.644 0.4-0.651 1.063-0.014 1.474l5.712 3.69c0.637 0.411 1.158 0.127 1.158-0.63v-2.374h12.409c3.158 0 6.128-1.23 8.361-3.463 1.424-1.424 2.44-3.148 2.99-5.029-0.985 0.368-2.033 0.606-3.125 0.691-1.492 3.038-4.619 5.135-8.226 5.135zM28.718 0c-4.985 0-9.026 4.041-9.026 9.026s4.041 9.026 9.026 9.026 9.026-4.041 9.026-9.026-4.041-9.026-9.026-9.026zM30.392 13.827h-1.728v-6.822c-0.635 0.576-1.433 1.004-2.407 1.285v-1.713c0.473-0.118 0.975-0.325 1.506-0.62 0.532-0.325 0.975-0.665 1.329-1.034h1.3v8.904z'],
|
||||||
'menu': ['0 0 22 32', 'M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z']
|
'menu': ['0 0 22 32', 'M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z']
|
||||||
};
|
};
|
||||||
this.getSVG = (type) => {
|
this.getSVG = (type) => {
|
||||||
@@ -63,10 +63,10 @@ class APlayer {
|
|||||||
this.mode = option.mode;
|
this.mode = option.mode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse second to 00:00 format
|
* Parse second to 00:00 format. 00:00:00 if audio is over an hour long.
|
||||||
*
|
*
|
||||||
* @param {Number} second
|
* @param {Number} second
|
||||||
* @return {String} 00:00 format
|
* @return {String} 00:00 format. 00:00:00 if over an hour long.
|
||||||
*/
|
*/
|
||||||
this.secondToTime = (second) => {
|
this.secondToTime = (second) => {
|
||||||
const add0 = (num) => {
|
const add0 = (num) => {
|
||||||
@@ -74,7 +74,9 @@ class APlayer {
|
|||||||
};
|
};
|
||||||
const min = parseInt(second / 60);
|
const min = parseInt(second / 60);
|
||||||
const sec = parseInt(second - min * 60);
|
const sec = parseInt(second - min * 60);
|
||||||
return add0(min) + ':' + add0(sec);
|
const hours = parseInt(min / 60);
|
||||||
|
const minAdjust = parseInt((second / 60) - (60 * parseInt((second / 60) / 60)));
|
||||||
|
return second >= 3600 ? add0(hours) + ':' + add0(minAdjust) + ':' + add0(sec) : add0(min) + ':' + add0(sec);
|
||||||
};
|
};
|
||||||
|
|
||||||
// save lrc
|
// save lrc
|
||||||
@@ -110,8 +112,8 @@ class APlayer {
|
|||||||
for (let i = 0; i < this.lrc.length; i++) {
|
for (let i = 0; i < this.lrc.length; i++) {
|
||||||
if (currentTime >= this.lrc[i][0] && (!this.lrc[i + 1] || currentTime < this.lrc[i + 1][0])) {
|
if (currentTime >= this.lrc[i][0] && (!this.lrc[i + 1] || currentTime < this.lrc[i + 1][0])) {
|
||||||
this.lrcIndex = i;
|
this.lrcIndex = i;
|
||||||
this.lrcContents.style.transform = `translateY(${-this.lrcIndex * 20}px)`;
|
this.lrcContents.style.transform = `translateY(${-this.lrcIndex * 16}px)`;
|
||||||
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 20}px)`;
|
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 16}px)`;
|
||||||
this.lrcContents.getElementsByClassName('aplayer-lrc-current')[0].classList.remove('aplayer-lrc-current');
|
this.lrcContents.getElementsByClassName('aplayer-lrc-current')[0].classList.remove('aplayer-lrc-current');
|
||||||
this.lrcContents.getElementsByTagName('p')[i].classList.add('aplayer-lrc-current');
|
this.lrcContents.getElementsByTagName('p')[i].classList.add('aplayer-lrc-current');
|
||||||
}
|
}
|
||||||
@@ -138,6 +140,14 @@ class APlayer {
|
|||||||
if (this.option.showlrc) {
|
if (this.option.showlrc) {
|
||||||
this.element.classList.add('aplayer-withlrc');
|
this.element.classList.add('aplayer-withlrc');
|
||||||
}
|
}
|
||||||
|
if (this.option.music.length > 1) {
|
||||||
|
this.element.classList.add('aplayer-list');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.multiple && this.mode !== 'circulation' && this.mode !== 'order') {
|
||||||
|
this.mode = 'circulation';
|
||||||
|
}
|
||||||
|
this.getRandomOrder();
|
||||||
|
|
||||||
// fill in HTML
|
// fill in HTML
|
||||||
let eleHTML = `
|
let eleHTML = `
|
||||||
@@ -170,7 +180,7 @@ class APlayer {
|
|||||||
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||||
</span>
|
</span>
|
||||||
<div class="aplayer-volume-wrap">
|
<div class="aplayer-volume-wrap">
|
||||||
<button class="aplayer-icon aplayer-icon-volume-down">`
|
<button class="aplayer-icon aplayer-icon-volume-down" ${this.isMobile ? 'style="display: none;"' : ''}>`
|
||||||
+ this.getSVG('volume-down')
|
+ this.getSVG('volume-down')
|
||||||
+ ` </button>
|
+ ` </button>
|
||||||
<div class="aplayer-volume-bar-wrap">
|
<div class="aplayer-volume-bar-wrap">
|
||||||
@@ -220,7 +230,6 @@ class APlayer {
|
|||||||
// fix the width of aplayer bar
|
// fix the width of aplayer bar
|
||||||
let bar = {};
|
let bar = {};
|
||||||
bar.barWrap = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
|
bar.barWrap = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
|
||||||
bar.barWrap.style.marginRight = this.element.getElementsByClassName('aplayer-time')[0].offsetWidth + 5 + 'px';
|
|
||||||
|
|
||||||
// switch to narrow style
|
// switch to narrow style
|
||||||
if (this.option.narrow) {
|
if (this.option.narrow) {
|
||||||
@@ -230,12 +239,7 @@ class APlayer {
|
|||||||
// play and pause button
|
// play and pause button
|
||||||
this.button = this.element.getElementsByClassName('aplayer-button')[0];
|
this.button = this.element.getElementsByClassName('aplayer-button')[0];
|
||||||
this.button.addEventListener('click', (e) => {
|
this.button.addEventListener('click', (e) => {
|
||||||
if (this.button.classList.contains('aplayer-play')) {
|
this.toggle();
|
||||||
this.play();
|
|
||||||
}
|
|
||||||
else if (this.button.classList.contains('aplayer-pause')) {
|
|
||||||
this.pause();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// click music list: change music
|
// click music list: change music
|
||||||
@@ -246,12 +250,7 @@ class APlayer {
|
|||||||
const musicIndex = parseInt(listItem[i].getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
const musicIndex = parseInt(listItem[i].getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
||||||
if (musicIndex !== this.playIndex) {
|
if (musicIndex !== this.playIndex) {
|
||||||
this.setMusic(musicIndex);
|
this.setMusic(musicIndex);
|
||||||
if (this.isMobile) {
|
this.play();
|
||||||
this.pause();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.play();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.toggle();
|
this.toggle();
|
||||||
@@ -376,17 +375,27 @@ class APlayer {
|
|||||||
// mode control
|
// mode control
|
||||||
const modeEle = this.element.getElementsByClassName('aplayer-icon-mode')[0];
|
const modeEle = this.element.getElementsByClassName('aplayer-icon-mode')[0];
|
||||||
modeEle.addEventListener('click', () => {
|
modeEle.addEventListener('click', () => {
|
||||||
if (this.mode === 'random') {
|
if (this.multiple) {
|
||||||
this.mode = 'single';
|
if (this.mode === 'random') {
|
||||||
|
this.mode = 'single';
|
||||||
|
}
|
||||||
|
else if (this.mode === 'single') {
|
||||||
|
this.mode = 'order';
|
||||||
|
}
|
||||||
|
else if (this.mode === 'order') {
|
||||||
|
this.mode = 'circulation';
|
||||||
|
}
|
||||||
|
else if (this.mode === 'circulation') {
|
||||||
|
this.mode = 'random';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (this.mode === 'single') {
|
else {
|
||||||
this.mode = 'order';
|
if (this.mode === 'circulation') {
|
||||||
}
|
this.mode = 'order';
|
||||||
else if (this.mode === 'order') {
|
}
|
||||||
this.mode = 'circulation';
|
else {
|
||||||
}
|
this.mode = 'circulation';
|
||||||
else if (this.mode === 'circulation') {
|
}
|
||||||
this.mode = 'random';
|
|
||||||
}
|
}
|
||||||
modeEle.innerHTML = this.getSVG(this.mode);
|
modeEle.innerHTML = this.getSVG(this.mode);
|
||||||
this.audio.loop = !(this.multiple || this.mode === 'order');
|
this.audio.loop = !(this.multiple || this.mode === 'order');
|
||||||
@@ -407,8 +416,7 @@ class APlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.mode === 'random') {
|
if (this.mode === 'random') {
|
||||||
let random = parseInt(Math.random() * this.option.music.length);
|
this.setMusic(this.randomOrder[0]);
|
||||||
this.setMusic(random);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.setMusic(0);
|
this.setMusic(0);
|
||||||
@@ -455,12 +463,15 @@ class APlayer {
|
|||||||
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
|
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
|
||||||
this.audio = document.createElement("audio");
|
this.audio = document.createElement("audio");
|
||||||
this.audio.src = this.music.url;
|
this.audio.src = this.music.url;
|
||||||
if (this.option.preload) {
|
this.audio.preload = this.option.preload ? this.option.preload : 'auto';
|
||||||
this.audio.preload = this.option.preload;
|
|
||||||
}
|
this.audio.addEventListener('play', () => {
|
||||||
else {
|
this.play();
|
||||||
this.audio.preload = this.isMobile ? 'none' : 'metadata';
|
});
|
||||||
}
|
|
||||||
|
this.audio.addEventListener('pause', () => {
|
||||||
|
this.pause();
|
||||||
|
});
|
||||||
|
|
||||||
// show audio time: the metadata has loaded or changed
|
// show audio time: the metadata has loaded or changed
|
||||||
this.audio.addEventListener('durationchange', () => {
|
this.audio.addEventListener('durationchange', () => {
|
||||||
@@ -497,12 +508,7 @@ class APlayer {
|
|||||||
}
|
}
|
||||||
if (this.audio.currentTime !== 0) {
|
if (this.audio.currentTime !== 0) {
|
||||||
if (this.mode === 'random') {
|
if (this.mode === 'random') {
|
||||||
let random = parseInt(Math.random() * this.option.music.length);
|
this.setMusic(this.nextRandomNum());
|
||||||
if (random === this.playIndex) {
|
|
||||||
random++;
|
|
||||||
random = random % this.option.music.length;
|
|
||||||
}
|
|
||||||
this.setMusic(random);
|
|
||||||
}
|
}
|
||||||
else if (this.mode === 'single') {
|
else if (this.mode === 'single') {
|
||||||
this.setMusic(this.playIndex);
|
this.setMusic(this.playIndex);
|
||||||
@@ -688,7 +694,7 @@ class APlayer {
|
|||||||
if (Object.prototype.toString.call(time) === '[object Number]') {
|
if (Object.prototype.toString.call(time) === '[object Number]') {
|
||||||
this.audio.currentTime = time;
|
this.audio.currentTime = time;
|
||||||
}
|
}
|
||||||
if (this.audio.paused) {
|
if (this.button.classList.contains('aplayer-play')) {
|
||||||
this.button.classList.remove('aplayer-play');
|
this.button.classList.remove('aplayer-play');
|
||||||
this.button.classList.add('aplayer-pause');
|
this.button.classList.add('aplayer-pause');
|
||||||
this.button.innerHTML = '';
|
this.button.innerHTML = '';
|
||||||
@@ -727,7 +733,7 @@ class APlayer {
|
|||||||
* Pause music
|
* Pause music
|
||||||
*/
|
*/
|
||||||
pause() {
|
pause() {
|
||||||
if (!this.audio.paused || this.ended) {
|
if (this.button.classList.contains('aplayer-pause') || this.ended) {
|
||||||
this.ended = false;
|
this.ended = false;
|
||||||
this.button.classList.remove('aplayer-pause');
|
this.button.classList.remove('aplayer-pause');
|
||||||
this.button.classList.add('aplayer-play');
|
this.button.classList.add('aplayer-play');
|
||||||
@@ -776,13 +782,63 @@ class APlayer {
|
|||||||
* toggle between play and pause
|
* toggle between play and pause
|
||||||
*/
|
*/
|
||||||
toggle() {
|
toggle() {
|
||||||
if (this.audio.paused) {
|
if (this.button.classList.contains('aplayer-play')) {
|
||||||
this.play();
|
this.play();
|
||||||
}
|
}
|
||||||
else {
|
else if (this.button.classList.contains('aplayer-pause')) {
|
||||||
this.pause();
|
this.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get random order, using Fisher–Yates shuffle
|
||||||
|
*/
|
||||||
|
getRandomOrder() {
|
||||||
|
function random(min, max) {
|
||||||
|
if (max == null) {
|
||||||
|
max = min;
|
||||||
|
min = 0;
|
||||||
|
}
|
||||||
|
return min + Math.floor(Math.random() * (max - min + 1));
|
||||||
|
}
|
||||||
|
function shuffle(arr) {
|
||||||
|
var length = arr.length,
|
||||||
|
shuffled = new Array(length);
|
||||||
|
for (var index = 0, rand; index < length; index++) {
|
||||||
|
rand = random(0, index);
|
||||||
|
if (rand !== index) shuffled[index] = shuffled[rand];
|
||||||
|
shuffled[rand] = arr[index];
|
||||||
|
}
|
||||||
|
return shuffled;
|
||||||
|
}
|
||||||
|
if (this.multiple) {
|
||||||
|
if (!this.normalOrder) {
|
||||||
|
this.normalOrder = [];
|
||||||
|
for (let i = 0; i < this.option.music.length; i++) {
|
||||||
|
this.normalOrder[i] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.randomOrder = shuffle(this.normalOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get next random number
|
||||||
|
*/
|
||||||
|
nextRandomNum() {
|
||||||
|
if (this.multiple) {
|
||||||
|
let index = this.randomOrder.indexOf(this.playIndex);
|
||||||
|
if (index === this.randomOrder.length - 1) {
|
||||||
|
return this.randomOrder[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.randomOrder[index + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = APlayer;
|
module.exports = APlayer;
|
||||||
+53
-22
@@ -1,6 +1,6 @@
|
|||||||
$aplayer-height: 66px;
|
$aplayer-height: 66px;
|
||||||
$lrc-height: 40px;
|
$lrc-height: 30px;
|
||||||
$aplayer-height-lrc: $aplayer-height + $lrc-height;
|
$aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||||
|
|
||||||
.aplayer-narrow {
|
.aplayer-narrow {
|
||||||
width: $aplayer-height;
|
width: $aplayer-height;
|
||||||
@@ -13,16 +13,32 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
&.aplayer-narrow {
|
&.aplayer-narrow {
|
||||||
width: $aplayer-height-lrc;
|
width: $aplayer-height-lrc;
|
||||||
}
|
}
|
||||||
&.aplayer .aplayer-pic {
|
&.aplayer {
|
||||||
height: $aplayer-height-lrc;
|
.aplayer-pic {
|
||||||
width: $aplayer-height-lrc;
|
height: $aplayer-height-lrc;
|
||||||
|
width: $aplayer-height-lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aplayer-info {
|
||||||
|
margin-left: $aplayer-height-lrc;
|
||||||
|
height: $aplayer-height-lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aplayer-lrc {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aplayer-info {
|
||||||
|
padding: 10px 7px 0 7px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&.aplayer .aplayer-info {
|
}
|
||||||
margin-left: $aplayer-height-lrc;
|
|
||||||
height: $aplayer-height-lrc;
|
.aplayer-list {
|
||||||
}
|
&.aplayer {
|
||||||
&.aplayer .aplayer-lrc {
|
.aplayer-info {
|
||||||
display: block;
|
border-bottom: 1px solid #e9e9e9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +65,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
opacity: .8;
|
opacity: .8;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
margin: 0;
|
||||||
|
display: inline;
|
||||||
|
|
||||||
.aplayer-fill {
|
.aplayer-fill {
|
||||||
transition: all .2s ease-in-out;
|
transition: all .2s ease-in-out;
|
||||||
@@ -132,7 +151,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
margin-bottom: 13px;
|
margin: 0 0 13px 5px;
|
||||||
|
user-select: text;
|
||||||
|
cursor: default;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
|
||||||
.aplayer-title {
|
.aplayer-title {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@@ -146,11 +168,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
|
|
||||||
.aplayer-controller {
|
.aplayer-controller {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
.aplayer-bar-wrap {
|
.aplayer-bar-wrap {
|
||||||
margin: 0 140px 0 5px;
|
margin: 0 0 0 5px;
|
||||||
padding: 4px 0;
|
padding: 4px 0;
|
||||||
cursor: pointer !important;
|
cursor: pointer !important;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
.aplayer-bar {
|
.aplayer-bar {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -192,12 +216,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.aplayer-time {
|
.aplayer-time {
|
||||||
position: absolute;
|
position: relative;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: -3px;
|
bottom: 3px;
|
||||||
height: 17px;
|
height: 17px;
|
||||||
color: #999;
|
color: #999;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
|
padding-left: 7px;
|
||||||
|
|
||||||
.aplayer-time-inner {
|
.aplayer-time-inner {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
@@ -280,7 +305,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
background: #fff;
|
background: #fff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: -10px 0 10px;
|
margin: -10px 0 7px;
|
||||||
|
|
||||||
&:before {
|
&:before {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -306,17 +331,17 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 33%;
|
height: 33%;
|
||||||
content: ' ';
|
content: ' ';
|
||||||
background: -moz-linear-gradient(bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
|
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 100%);
|
||||||
background: -webkit-linear-gradient(bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
|
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
|
||||||
background: linear-gradient(to top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
|
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
|
||||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 );
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ccffffff',GradientType=0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #666;
|
color: #666;
|
||||||
line-height: 20px !important;
|
line-height: 16px !important;
|
||||||
height: 20px !important;
|
height: 16px !important;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
transition: all 0.5s ease-out;
|
transition: all 0.5s ease-out;
|
||||||
@@ -331,6 +356,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
.aplayer-lrc-contents {
|
.aplayer-lrc-contents {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
transition: all 0.5s ease-out;
|
transition: all 0.5s ease-out;
|
||||||
|
user-select: text;
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,6 +400,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
|||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: #efefef;
|
background: #efefef;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user