7 Commits
Author SHA1 Message Date
DIYgod c1c83d3c96 optimize the style of aplayer with lrc 2016-10-11 11:24:03 +08:00
DIYgod 89992c84c9 fix aplayer-bar width 2016-10-11 10:02:15 +08:00
Wenjie Fan 58a53e324c Merge pull request #76 from argvil19/display-date
display hh:mm:ss format when audio is over an hour long
2016-10-10 20:41:15 -05:00
Argenis Villasmil 02058ad17f display hh:mm:ss format when audio is over an hour long 2016-10-10 21:01:30 -04:00
DIYgod d7365d9546 Make music title and lrc selectable; click list to play next song in mobile: close #69 2016-09-30 11:13:35 +08:00
DIYgod 1386beaa27 Fix UMD bug 2016-09-26 01:50:13 +08:00
DIYgod 62d146a9dc Scrollbar style, close #72 2016-09-20 12:12:21 +08:00
8 changed files with 92 additions and 49 deletions
+7 -1
View File
@@ -54,7 +54,7 @@ var option = {
mutex: true, // Optional, pause other players when this player playing
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
mode: 'random', // Optional, play mode, can be `random` `single` `circulation`(loop) `order`(no loop), default: `circulation`
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: '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
music: { // Required, music info, see: ###With playlist
title: 'Preparation', // Required, music title
@@ -74,6 +74,12 @@ var option = {
+ `ap.toggle()` // Toggle between play and pause
+ `ap.volume(percentage)` // Set volume
+ `ap.on(event, handler)` // Event binding
+ `ap.setMusic(index)` // Switch music
+ `ap.lrc` // Lrc time and text
+ `ap.playIndex` // Current playing index
+ `ap.audio` // Return native video, most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
+ `dp.audio.currentTime` // Returns the current playback position
+ Most [native api](http://www.w3schools.com/tags/ref_av_dom.asp)
#### Event binding
+1 -1
View File
@@ -107,7 +107,7 @@ var ap5 = new APlayer({
mutex: true,
theme: '#ad7a86',
mode: 'random',
listmaxheight: '60px',
listmaxheight: '80px',
music: [
{
title: 'あっちゅ~ま青春!',
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,11 +1,11 @@
{
"name": "aplayer",
"version": "1.5.2",
"version": "1.5.4",
"description": "Wow, such a beautiful html5 music player",
"main": "dist/APlayer.min.js",
"scripts": {
"test": "webpack",
"start": "webpack-dev-server --hot --progress --inline"
"start": "webpack-dev-server --hot --progress --inline --host 0.0.0.0"
},
"repository": {
"type": "git",
+15 -21
View File
@@ -1,4 +1,4 @@
console.log("\n %c APlayer 1.5.2 %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.4 %c http://aplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
require('./APlayer.scss');
@@ -63,10 +63,10 @@ class APlayer {
this.mode = option.mode;
/**
* Parse second to 00:00 format
* Parse second to 00:00 format. 00:00:00 if audio is over an hour long.
*
* @param {Number} second
* @return {String} 00:00 format
* @return {String} 00:00 format. 00:00:00 if over an hour long.
*/
this.secondToTime = (second) => {
const add0 = (num) => {
@@ -74,7 +74,9 @@ class APlayer {
};
const min = parseInt(second / 60);
const sec = parseInt(second - min * 60);
return add0(min) + ':' + add0(sec);
const hours = parseInt(min / 60);
const minAdjust = parseInt((second / 60) - (60 * parseInt((second / 60) / 60)));
return second >= 3600 ? add0(hours) + ':' + add0(minAdjust) + ':' + add0(sec) : add0(min) + ':' + add0(sec);
};
// save lrc
@@ -110,8 +112,8 @@ class APlayer {
for (let i = 0; i < this.lrc.length; i++) {
if (currentTime >= this.lrc[i][0] && (!this.lrc[i + 1] || currentTime < this.lrc[i + 1][0])) {
this.lrcIndex = i;
this.lrcContents.style.transform = `translateY(${-this.lrcIndex * 20}px)`;
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 20}px)`;
this.lrcContents.style.transform = `translateY(${-this.lrcIndex * 16}px)`;
this.lrcContents.style.webkitTransform = `translateY(${-this.lrcIndex * 16}px)`;
this.lrcContents.getElementsByClassName('aplayer-lrc-current')[0].classList.remove('aplayer-lrc-current');
this.lrcContents.getElementsByTagName('p')[i].classList.add('aplayer-lrc-current');
}
@@ -138,6 +140,9 @@ class APlayer {
if (this.option.showlrc) {
this.element.classList.add('aplayer-withlrc');
}
if (this.option.music.length > 1) {
this.element.classList.add('aplayer-list');
}
// fill in HTML
let eleHTML = `
@@ -170,7 +175,7 @@ class APlayer {
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
</span>
<div class="aplayer-volume-wrap">
<button class="aplayer-icon aplayer-icon-volume-down">`
<button class="aplayer-icon aplayer-icon-volume-down" ${this.isMobile ? 'style="display: none;"' : ''}>`
+ this.getSVG('volume-down')
+ ` </button>
<div class="aplayer-volume-bar-wrap">
@@ -220,7 +225,6 @@ class APlayer {
// fix the width of aplayer bar
let bar = {};
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
if (this.option.narrow) {
@@ -246,12 +250,7 @@ class APlayer {
const musicIndex = parseInt(listItem[i].getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
if (musicIndex !== this.playIndex) {
this.setMusic(musicIndex);
if (this.isMobile) {
this.pause();
}
else {
this.play();
}
this.play();
}
else {
this.toggle();
@@ -455,12 +454,7 @@ class APlayer {
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
this.audio = document.createElement("audio");
this.audio.src = this.music.url;
if (this.option.preload) {
this.audio.preload = this.option.preload;
}
else {
this.audio.preload = this.isMobile ? 'none' : 'metadata';
}
this.audio.preload = this.option.preload ? this.option.preload : 'auto';
// show audio time: the metadata has loaded or changed
this.audio.addEventListener('durationchange', () => {
@@ -785,4 +779,4 @@ class APlayer {
}
}
export {APlayer};
module.exports = APlayer;
+63 -21
View File
@@ -1,6 +1,6 @@
$aplayer-height: 66px;
$lrc-height: 40px;
$aplayer-height-lrc: $aplayer-height + $lrc-height;
$lrc-height: 30px;
$aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
.aplayer-narrow {
width: $aplayer-height;
@@ -13,16 +13,32 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
&.aplayer-narrow {
width: $aplayer-height-lrc;
}
&.aplayer .aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
&.aplayer {
.aplayer-pic {
height: $aplayer-height-lrc;
width: $aplayer-height-lrc;
}
.aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
}
.aplayer-lrc {
display: block;
}
.aplayer-info {
padding: 10px 7px 0 7px;
}
}
&.aplayer .aplayer-info {
margin-left: $aplayer-height-lrc;
height: $aplayer-height-lrc;
}
&.aplayer .aplayer-lrc {
display: block;
}
.aplayer-list {
&.aplayer {
.aplayer-info {
border-bottom: 1px solid #e9e9e9;
}
}
}
@@ -133,6 +149,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: 13px;
user-select: text;
cursor: default;
padding-bottom: 2px;
.aplayer-title {
font-size: 14px;
@@ -146,11 +165,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-controller {
position: relative;
display: flex;
.aplayer-bar-wrap {
margin: 0 140px 0 5px;
margin: 0 0 0 5px;
padding: 4px 0;
cursor: pointer !important;
flex: 1;
.aplayer-bar {
position: relative;
@@ -192,12 +213,13 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
}
.aplayer-time {
position: absolute;
position: relative;
right: 0;
bottom: -3px;
bottom: 3px;
height: 17px;
color: #999;
font-size: 11px;
padding-left: 7px;
.aplayer-time-inner {
vertical-align: middle;
@@ -280,7 +302,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
background: #fff;
text-align: center;
overflow: hidden;
margin: -10px 0 10px;
margin: -10px 0 7px;
&:before {
position: absolute;
@@ -306,17 +328,17 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
width: 100%;
height: 33%;
content: ' ';
background: -moz-linear-gradient(bottom, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);
background: -webkit-linear-gradient(bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
background: linear-gradient(to top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 );
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 100%);
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ccffffff',GradientType=0 );
}
p {
font-size: 12px;
color: #666;
line-height: 20px !important;
height: 20px !important;
line-height: 16px !important;
height: 16px !important;
padding: 0 !important;
margin: 0 !important;
transition: all 0.5s ease-out;
@@ -331,6 +353,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-lrc-contents {
width: 100%;
transition: all 0.5s ease-out;
user-select: text;
cursor: default;
}
}
@@ -343,6 +367,20 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
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;
@@ -359,6 +397,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
transition: all 0.2s ease;
overflow: hidden;
&:first-child {
border-top: none;
}
&:hover {
background: #efefef;
}
+1
View File
@@ -14,6 +14,7 @@ module.exports = {
output: {
path: BUILD_PATH,
filename: 'APlayer.min.js',
library: 'APlayer',
libraryTarget: 'umd',
umdNamedDefine: true
},