23 Commits
Author SHA1 Message Date
DIYgod d2b673db39 fix long list title display error 2016-07-11 11:22:15 +08:00
DIYgod d116c75a09 improve UI; new API: toggle 2016-07-11 10:16:53 +08:00
DIYgod a5cc501f3b font -> inline svg 2016-07-08 16:15:22 +08:00
DIYgod 96b49d2734 change License 2016-07-08 12:20:11 +08:00
DIYgod 9f9ded6e1e API: play volume; Bug: encodeURI image link 2016-07-08 11:25:34 +08:00
DIYgod 12fc04957d new option: preload 2016-06-13 14:23:51 +08:00
DIYgod c5776b2a78 fix bugs in HTML 2016-06-13 14:06:27 +08:00
DIYgod 548faa4bf3 add related project: 163music-APlayer-you-get-docker 2016-05-15 18:32:58 +08:00
DIYgod 91566de67a new npm version 2016-05-14 22:38:42 +08:00
DIYgod 7b8ad10c04 Fix bug: multiple ended event in iOS; clicking list error in mobile 2016-05-14 22:37:48 +08:00
DIYgod 47270238cb Fix bug: Symbol is not defined 2016-05-14 21:40:03 +08:00
DIYgod 04e950b1eb bugs with mutex 2016-05-14 20:04:41 +08:00
DIYgod 54f9d5dcf9 new demo link 2016-05-14 15:44:20 +08:00
DIYgod 2b6ba28167 rm CNAME 2016-05-14 15:13:35 +08:00
DIYgod 10ad8cd38d CNAME 2016-05-14 00:55:46 +08:00
DIYgod adb2cd4ed8 change demo link 2016-05-12 18:11:53 +08:00
DIYgod f1bc748330 optimize 2016-05-10 01:00:16 +08:00
DIYgod 008552940f new demo page 2016-05-05 20:59:31 +08:00
DIYgod 40d95344fd fix drag bug, new option: loop 2016-05-05 20:57:30 +08:00
Wenjie Fan da71e49dc0 Merge pull request #41 from micooz/improve-mutex
Improve mutex
2016-05-02 00:02:09 +08:00
Micooz b019271309 update dist/* 2016-05-01 21:27:36 +08:00
Micooz 5206eed8e5 deprecate vars outside class 2016-05-01 21:27:17 +08:00
Micooz 82b7f777f6 remove redundant semicolon 2016-05-01 21:00:29 +08:00
17 changed files with 285 additions and 205 deletions
+37
View File
@@ -0,0 +1,37 @@
The Star And Thank Author License (SATA)
Copyright (c) 2016 DIYgod(i@html.love)
Project Url: https://github.com/DIYgod/APlayer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
And wait, the most important, you shall star/+1/like the project(s) in project url
section above first, and then thank the author(s) in Copyright section.
Here are some suggested ways:
- Email the authors a thank-you letter, and make friends with him/her/them.
- Report bugs or issues.
- Tell friends what a wonderful project this is.
- And, sure, you can just express thanks in your mind without telling the world.
Contributors of this project by forking have the option to add his/her name and
forked project url at copyright and project url sections, but shall not delete
or modify anything else in these two sections.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+15 -7
View File
@@ -7,13 +7,13 @@
[![Travis](https://img.shields.io/travis/DIYgod/APlayer.svg?style=flat-square)](https://travis-ci.org/DIYgod/APlayer)
[![%e2%9d%a4](https://img.shields.io/badge/made%20with-%e2%9d%a4-ff69b4.svg?style=flat-square)](https://www.anotherhome.net/)
Wow, such a beautiful html5 music player
> Wow, such a beautiful html5 music player
## Introduction
UI 参考网易云音乐外链播放器
[Demo](https://www.anotherhome.net/file/APlayer)
[Demo](http://aplayer.js.org)
Screenshot
![image](https://i.imgur.com/JDrJXCr.png)
@@ -57,6 +57,8 @@ var option = {
showlrc: 0, // Optional, show lrc, can be 0, 1, 2, see: ###With lrc
mutex: true, // Optional, pause other players when this player playing
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
loop: true, // Optional, loop play music, default: true
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'metadata' in Desktop, 'none' in mobile
music: { // Required, music info, see: ###With playlist
title: 'Preparation', // Required, music title
author: 'Hans Zimmer/Richard Harvey', // Required, music author
@@ -70,8 +72,12 @@ var option = {
#### API
+ `ap.init()`
+ `ap.play()`
+ `ap.pause()`
+ `ap.play()` // Resume play
+ `ap.play(time)` // Set currentTime
+ `ap.pause()` // Pause
+ `ap.toggle()` // Toggle between play and pause
+ `ap.volume(percentage)` // Set volume
+ `ap.on(event, handler)` // Event binding
#### Event binding
@@ -190,11 +196,13 @@ $ npm run build
## Related Projects
+ [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin)
- [APlayer-Typecho-Plugin](https://github.com/zgq354/APlayer-Typecho-Plugin)
+ [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer)
- [hexo-tag-aplayer](https://github.com/grzhan/hexo-tag-aplayer)
- [163music-APlayer-you-get-docker](https://github.com/YUX-IO/163music-APlayer-you-get-docker)
## LICENSE
MIT © [DIYgod](http://github.com/DIYgod)
[The Star And Thank Author License (SATA)](https://github.com/DIYgod/APlayer/blob/master/LICENSE)
+19 -18
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
BIN
View File
Binary file not shown.
-20
View File
@@ -1,20 +0,0 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2016 by original authors @ fontello.com</metadata>
<defs>
<font id="fontello" horiz-adv-x="1000" >
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="volume-off" unicode="&#xe800;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z" horiz-adv-x="428.6" />
<glyph glyph-name="volume-down" unicode="&#xe801;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z m214-304q0-42-24-79t-63-52q-5-3-14-3-14 0-25 10t-10 26q0 12 6 20t17 14 19 12 16 20 6 32-6 32-16 20-19 12-17 14-6 20q0 15 10 26t25 10q9 0 14-3 39-15 63-52t24-79z" horiz-adv-x="642.9" />
<glyph glyph-name="volume-up" unicode="&#xe802;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z m214-304q0-42-24-79t-63-52q-5-3-14-3-14 0-25 10t-10 26q0 12 6 20t17 14 19 12 16 20 6 32-6 32-16 20-19 12-17 14-6 20q0 15 10 26t25 10q9 0 14-3 39-15 63-52t24-79z m143 0q0-85-48-158t-125-105q-8-3-14-3-15 0-26 11t-10 25q0 22 21 33 32 16 43 25 41 30 64 75t23 97-23 97-64 75q-11 9-43 25-21 11-21 33 0 14 10 25t25 11q7 0 15-3 78-33 125-105t48-158z m143 0q0-128-71-236t-189-158q-7-3-14-3-15 0-26 11t-10 25q0 20 22 33 4 2 12 6t13 6q25 14 45 28 69 51 108 127t38 161-38 161-108 127q-20 14-45 28-4 3-13 6t-12 6q-22 13-22 33 0 14 10 25t26 11q7 0 14-3 118-51 189-158t71-236z" horiz-adv-x="928.6" />
<glyph glyph-name="loop" unicode="&#xe803;" d="m800 540q42 0 71-29t29-71l0-290q0-40-29-70t-71-30l-700 0q-40 0-70 30t-30 70l0 290q0 42 30 71t70 29l250 0 0 110 200-180-200-180 0 110-210 0 0-210 620 0 0 210-150 0 0 140 190 0z" horiz-adv-x="900" />
<glyph glyph-name="play" unicode="&#xe806;" d="m486 376q14-10 14-26 0-14-14-24l-428-266q-24-16-41-6t-17 40l0 514q0 30 17 40t41-6z" horiz-adv-x="500" />
<glyph glyph-name="pause" unicode="&#xe807;" d="m440 700q90 0 90-64l0-570q0-66-90-66t-90 66l0 570q0 64 90 64z m-350 0q90 0 90-64l0-570q0-66-90-66t-90 66l0 570q0 64 90 64z" horiz-adv-x="530" />
<glyph glyph-name="to-start" unicode="&#xe808;" d="m174 350q0 14 14 24l364 228q20 14 34 5t14-35l0-442q0-26-14-35t-34 5l-364 228q-14 10-14 22z m-174 234q0 58 76 58 74 0 74-58l0-466q0-58-74-58-76 0-76 58l0 466z" horiz-adv-x="600" />
<glyph glyph-name="to-end" unicode="&#xe809;" d="m412 374q14-10 14-24 0-12-14-22l-362-228q-22-14-36-5t-14 35l0 442q0 26 14 35t36-5z m114 268q74 0 74-58l0-466q0-58-74-58-76 0-76 58l0 466q0 58 76 58z" horiz-adv-x="600" />
<glyph glyph-name="menu" unicode="&#xe80b;" d="m650 400q22 0 36-15t14-35-15-35-35-15l-600 0q-20 0-35 15t-15 35 14 35 36 15l600 0z m-600 100q-20 0-35 15t-15 35 14 35 36 15l600 0q22 0 36-15t14-35-15-35-35-15l-600 0z m600-300q22 0 36-15t14-35-15-35-35-15l-600 0q-20 0-35 15t-15 35 14 35 36 15l600 0z" horiz-adv-x="700" />
</font>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 3.1 KiB

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "aplayer",
"version": "1.4.2",
"version": "1.4.8",
"description": "Wow, such a beautiful html5 music player",
"main": "dist/APlayer.min.js",
"scripts": {
@@ -18,7 +18,7 @@
"html5"
],
"author": "DIYgod",
"license": "MIT",
"license": "SATA",
"bugs": {
"url": "https://github.com/DIYgod/APlayer/issues"
},
+160 -58
View File
@@ -1,5 +1,4 @@
(() => {
let APlayers = [];
((instances) => {
class APlayer {
/**
@@ -9,8 +8,25 @@
* @constructor
*/
constructor(option) {
this.svg = {
'play': ['0 0 16 31', 'M15.552 15.168q0.448 0.32 0.448 0.832 0 0.448-0.448 0.768l-13.696 8.512q-0.768 0.512-1.312 0.192t-0.544-1.28v-16.448q0-0.96 0.544-1.28t1.312 0.192z'],
'pause': ['0 0 17 32', 'M14.080 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048zM2.88 4.8q2.88 0 2.88 2.048v18.24q0 2.112-2.88 2.112t-2.88-2.112v-18.24q0-2.048 2.88-2.048z'],
'volume-up': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528zM25.152 16q0 2.72-1.536 5.056t-4 3.36q-0.256 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.704 0.672-1.056 1.024-0.512 1.376-0.8 1.312-0.96 2.048-2.4t0.736-3.104-0.736-3.104-2.048-2.4q-0.352-0.288-1.376-0.8-0.672-0.352-0.672-1.056 0-0.448 0.32-0.8t0.8-0.352q0.224 0 0.48 0.096 2.496 1.056 4 3.36t1.536 5.056zM29.728 16q0 4.096-2.272 7.552t-6.048 5.056q-0.224 0.096-0.448 0.096-0.48 0-0.832-0.352t-0.32-0.8q0-0.64 0.704-1.056 0.128-0.064 0.384-0.192t0.416-0.192q0.8-0.448 1.44-0.896 2.208-1.632 3.456-4.064t1.216-5.152-1.216-5.152-3.456-4.064q-0.64-0.448-1.44-0.896-0.128-0.096-0.416-0.192t-0.384-0.192q-0.704-0.416-0.704-1.056 0-0.448 0.32-0.8t0.832-0.352q0.224 0 0.448 0.096 3.776 1.632 6.048 5.056t2.272 7.552z'],
'volume-down': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8zM20.576 16q0 1.344-0.768 2.528t-2.016 1.664q-0.16 0.096-0.448 0.096-0.448 0-0.8-0.32t-0.32-0.832q0-0.384 0.192-0.64t0.544-0.448 0.608-0.384 0.512-0.64 0.192-1.024-0.192-1.024-0.512-0.64-0.608-0.384-0.544-0.448-0.192-0.64q0-0.48 0.32-0.832t0.8-0.32q0.288 0 0.448 0.096 1.248 0.48 2.016 1.664t0.768 2.528z'],
'volume-off': ['0 0 28 32', 'M13.728 6.272v19.456q0 0.448-0.352 0.8t-0.8 0.32-0.8-0.32l-5.952-5.952h-4.672q-0.48 0-0.8-0.352t-0.352-0.8v-6.848q0-0.48 0.352-0.8t0.8-0.352h4.672l5.952-5.952q0.32-0.32 0.8-0.32t0.8 0.32 0.352 0.8z'],
'loop': ['0 0 29 32', 'M25.6 9.92q1.344 0 2.272 0.928t0.928 2.272v9.28q0 1.28-0.928 2.24t-2.272 0.96h-22.4q-1.28 0-2.24-0.96t-0.96-2.24v-9.28q0-1.344 0.96-2.272t2.24-0.928h8v-3.52l6.4 5.76-6.4 5.76v-3.52h-6.72v6.72h19.84v-6.72h-4.8v-4.48h6.080z'],
'menu': ['0 0 22 32', 'M20.8 14.4q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2zM1.6 11.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2zM20.8 20.8q0.704 0 1.152 0.48t0.448 1.12-0.48 1.12-1.12 0.48h-19.2q-0.64 0-1.12-0.48t-0.48-1.12 0.448-1.12 1.152-0.48h19.2z']
};
this.getSVG = (type) => {
return `
<svg xmlns:xlink="http://www.w3.org/1999/xlink" height="100%" version="1.1" viewBox="${this.svg[type][0]}" width="100%">
<use xlink:href="#aplayer-${type}"></use>
<path class="aplayer-fill" d="${this.svg[type][1]}" id="aplayer-${type}"></path>
</svg>
`;
};
this.isMobile = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i);
this.isMobile = /mobile/i.test(window.navigator.userAgent);
// compatibility: some mobile browsers don't suppose autoplay
if (this.isMobile) {
option.autoplay = false;
@@ -23,7 +39,8 @@
autoplay: false,
mutex: true,
showlrc: 0,
theme: '#b7daff'
theme: '#b7daff',
loop: true
};
for (let defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
@@ -36,7 +53,7 @@
this.option = option;
this.audios = [];
this.loop = true;
this.loop = option.loop;
/**
* Parse second to 00:00 format
@@ -127,12 +144,12 @@
// define APlayer events
this.eventTypes = ['play', 'pause', 'canplay', 'playing', 'ended', 'error'];
this.event = {};
for (let type of this.eventTypes) {
this.event[type] = [];
for (let i = 0; i < this.eventTypes.length; i++) {
this.event[this.eventTypes[i]] = [];
}
this.trigger = (type) => {
for (let func of this.event[type]) {
func();
for (let i = 0; i < this.event[type].length; i++) {
this.event[type][i]();
}
}
}
@@ -175,9 +192,11 @@
// fill in HTML
let eleHTML = `
<div class="aplayer-pic" ${(this.music.pic ? (`style="background-image: url("${encodeURI(this.music.pic)}");"`) : ``)}>
<div class="aplayer-pic" ${(this.music.pic ? (`style="background-image: url('${this.music.pic}');"`) : ``)}>
<div class="aplayer-button aplayer-play">
<i class="demo-icon aplayer-icon-play"></i>
<button class="aplayer-icon aplayer-icon-play">`
+ this.getSVG('play')
+ ` </button>
</div>
</div>
<div class="aplayer-info">
@@ -198,16 +217,25 @@
</div>
</div>
<div class="aplayer-time">
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
<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">
<i class="demo-icon aplayer-icon-volume-down"></i>
<button class="aplayer-icon aplayer-icon-volume-down">`
+ this.getSVG('volume-down')
+ ` </button>
<div class="aplayer-volume-bar-wrap">
<div class="aplayer-volume-bar">
<div class="aplayer-volume" style="height: 80%; background: ${this.option.theme};"></div>
</div>
</div>
</div>
<i class="demo-icon aplayer-icon-loop"></i>${(this.multiple ? `<i class="demo-icon aplayer-icon-menu"></i>` : ``)}
<button class="aplayer-icon aplayer-icon-loop${(this.loop ? `` : ` aplayer-noloop`)}">`
+ this.getSVG('loop')
+ ` </button>
${(this.multiple ? `<button class="aplayer-icon aplayer-icon-menu">`
+ this.getSVG('menu')
+ ` </button>` : ``)}
</div>
</div>
</div>`;
@@ -230,11 +258,19 @@
}
this.element.innerHTML = eleHTML;
// hide loop button in arrow container
if (this.element.offsetWidth < 300) {
this.element.getElementsByClassName('aplayer-icon-loop')[0].style.display = 'none';
}
this.ptime = this.element.getElementsByClassName('aplayer-ptime')[0];
if (this.element.getElementsByClassName('aplayer-info')[0].offsetWidth < 200) {
this.element.getElementsByClassName('aplayer-time')[0].classList.add('aplayer-time-narrow');
}
// fix the width of aplayer bar
this.element.getElementsByClassName('aplayer-bar-wrap')[0].style.marginRight = this.element.getElementsByClassName('aplayer-time')[0].offsetWidth + 5 + 'px';
this.bar = this.element.getElementsByClassName('aplayer-bar-wrap')[0];
this.bar.style.marginRight = this.element.getElementsByClassName('aplayer-time')[0].offsetWidth + 5 + 'px';
// switch to narrow style
if (this.option.narrow) {
@@ -260,8 +296,16 @@
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();
}
}
else {
this.toggle();
}
this.play();
});
}
}
@@ -270,7 +314,6 @@
this.playedBar = this.element.getElementsByClassName('aplayer-played')[0];
this.loadedBar = this.element.getElementsByClassName('aplayer-loaded')[0];
this.thumb = this.element.getElementsByClassName('aplayer-thumb')[0];
this.bar = this.element.getElementsByClassName('aplayer-bar')[0];
let barWidth;
this.bar.addEventListener('click', (event) => {
const e = event || window.event;
@@ -304,7 +347,14 @@
document.removeEventListener('mouseup', thumbUp);
document.removeEventListener('mousemove', thumbMove);
this.audio.currentTime = parseFloat(this.playedBar.style.width) / 100 * this.audio.duration;
this.play();
this.playedTime = setInterval(() => {
this.updateBar('played', this.audio.currentTime / this.audio.duration, 'width');
if (this.option.showlrc) {
this.updateLrc();
}
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(this.audio.currentTime);
this.trigger('playing');
}, 100);
};
this.thumb.addEventListener('mousedown', () => {
@@ -317,34 +367,33 @@
// control volume
this.volumeBar = this.element.getElementsByClassName('aplayer-volume')[0];
const volumeBarWrap = this.element.getElementsByClassName('aplayer-volume-bar')[0];
const volumeicon = this.element.getElementsByClassName('aplayer-time')[0].getElementsByTagName('i')[0];
this.volumeicon = this.element.getElementsByClassName('aplayer-time')[0].getElementsByTagName('button')[0];
const barHeight = 35;
this.element.getElementsByClassName('aplayer-volume-bar-wrap')[0].addEventListener('click', (event) => {
const e = event || window.event;
let percentage = (barHeight - e.clientY + getElementViewTop(volumeBarWrap)) / barHeight;
percentage = percentage > 0 ? percentage : 0;
percentage = percentage < 1 ? percentage : 1;
this.updateBar('volume', percentage, 'height');
this.audio.volume = percentage;
if (this.audio.muted) {
this.audio.muted = false;
}
if (percentage === 1) {
volumeicon.className = 'demo-icon aplayer-icon-volume-up';
}
else {
volumeicon.className = 'demo-icon aplayer-icon-volume-down';
}
this.volume(percentage);
});
volumeicon.addEventListener('click', () => {
this.volumeicon.addEventListener('click', () => {
if (this.audio.muted) {
this.audio.muted = false;
volumeicon.className = this.audio.volume === 1 ? 'demo-icon aplayer-icon-volume-up' : 'demo-icon aplayer-icon-volume-down';
this.volumeicon.className = this.audio.volume === 1 ? 'aplayer-icon aplayer-icon-volume-up' : 'aplayer-icon aplayer-icon-volume-down';
if (this.audio.volume === 1) {
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-up';
this.volumeicon.innerHTML = this.getSVG('volume-up');
}
else {
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-down';
this.volumeicon.innerHTML = this.getSVG('volume-down');
}
this.updateBar('volume', this.audio.volume, 'height');
}
else {
this.audio.muted = true;
volumeicon.className = 'demo-icon aplayer-icon-volume-off';
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-off';
this.volumeicon.innerHTML = this.getSVG('volume-off');
this.updateBar('volume', 0, 'height');
}
});
@@ -391,8 +440,9 @@
// toggle menu control
if (this.multiple) {
const list = this.element.getElementsByClassName('aplayer-list')[0];
list.style.height = list.offsetHeight + 'px';
this.element.getElementsByClassName('aplayer-icon-menu')[0].addEventListener('click', () => {
const list = this.element.getElementsByClassName('aplayer-list')[0];
if (!list.classList.contains('aplayer-list-hide')) {
list.classList.add('aplayer-list-hide');
}
@@ -404,8 +454,8 @@
this.setMusic(0);
APlayers.push(this);
};
instances.push(this);
}
/**
* Set music
@@ -420,7 +470,7 @@
// set html
if (this.music.pic) {
this.element.getElementsByClassName('aplayer-pic')[0].style.backgroundImage = `url(${encodeURI(this.music.pic)})`;
this.element.getElementsByClassName('aplayer-pic')[0].style.backgroundImage = `url('${this.music.pic}')`;
}
this.element.getElementsByClassName('aplayer-title')[0].innerHTML = this.music.title;
this.element.getElementsByClassName('aplayer-author')[0].innerHTML = ` - ${this.music.author}`;
@@ -441,7 +491,12 @@
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
this.audio = document.createElement("audio");
this.audio.src = this.music.url;
this.audio.preload = this.isMobile ? 'none' : 'metadata';
if (this.option.preload) {
this.audio.preload = this.option.preload;
}
else {
this.audio.preload = this.isMobile ? 'none' : 'metadata';
}
// show audio time: the metadata has loaded or changed
this.audio.addEventListener('durationchange', () => {
@@ -471,16 +526,23 @@
this.ended = false;
if (this.multiple) {
this.audio.addEventListener('ended', () => {
if (this.playIndex < this.option.music.length - 1) {
this.setMusic(++this.playIndex);
}
else if (this.loop) {
this.setMusic(0);
}
else if (!this.loop) {
if (this.isMobile) {
this.ended = true;
this.pause();
this.trigger('ended');
return;
}
if (this.audio.currentTime !== 0) {
if (this.playIndex < this.option.music.length - 1) {
this.setMusic(++this.playIndex);
}
else if (this.loop) {
this.setMusic(0);
}
else if (!this.loop) {
this.ended = true;
this.pause();
this.trigger('ended');
}
}
});
}
@@ -541,25 +603,31 @@
if (this.isMobile) {
this.pause();
}
};
}
/**
* Play music
*/
play() {
play(time) {
if (Object.prototype.toString.call(time) === '[object Number]') {
this.audio.currentTime = time;
}
if (this.audio.paused) {
this.button.classList.remove('aplayer-play');
this.button.classList.add('aplayer-pause');
this.button.innerHTML = '';
setTimeout(() => {
this.button.innerHTML = '<i class="demo-icon aplayer-icon-pause"></i>';
this.button.innerHTML = `
<button class="aplayer-icon aplayer-icon-pause">`
+ this.getSVG('pause')
+ ` </button>`;
}, 100);
// pause other players (Thanks @Aprikyblue)
if (this.option.mutex) {
for (let i = 0; i < APlayers.length; i++) {
if (this != APlayers[i]) {
APlayers[i].pause();
for (let i = 0; i < instances.length; i++) {
if (this != instances[i]) {
instances[i].pause();
}
}
}
@@ -572,12 +640,12 @@
if (this.option.showlrc) {
this.updateLrc();
}
this.element.getElementsByClassName('aplayer-ptime')[0].innerHTML = this.secondToTime(this.audio.currentTime);
this.ptime.innerHTML = this.secondToTime(this.audio.currentTime);
this.trigger('playing');
}, 100);
this.trigger('play');
}
};
}
/**
* Pause music
@@ -589,13 +657,35 @@
this.button.classList.add('aplayer-play');
this.button.innerHTML = '';
setTimeout(() => {
this.button.innerHTML = '<i class="demo-icon aplayer-icon-play"></i>';
this.button.innerHTML = `
<button class="aplayer-icon aplayer-icon-play">`
+ this.getSVG('play')
+ ` </button>`;
}, 100);
this.audio.pause();
clearInterval(this.playedTime);
this.trigger('pause');
}
};
}
/**
* Set volume
*/
volume(percentage) {
this.updateBar('volume', percentage, 'height');
this.audio.volume = percentage;
if (this.audio.muted) {
this.audio.muted = false;
}
if (percentage === 1) {
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-up';
this.volumeicon.innerHTML = this.getSVG('volume-up');
}
else {
this.volumeicon.className = 'aplayer-icon aplayer-icon-volume-down';
this.volumeicon.innerHTML = this.getSVG('volume-down');
}
}
/**
* attach event
@@ -605,12 +695,24 @@
this.event[name].push(func);
}
}
/**
* toggle between play and pause
*/
toggle() {
if (this.audio.paused) {
this.play();
}
else {
this.pause();
}
}
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = APlayer
module.exports = APlayer;
}
else {
window.APlayer = APlayer;
}
})();
})([]);
+49 -77
View File
@@ -2,17 +2,6 @@ $aplayer-height: 66px;
$lrc-height: 40px;
$aplayer-height-lrc: $aplayer-height + $lrc-height;
@font-face {
font-family: 'aplayer-fontello';
src: url('font/aplayer-fontello.eot?72550380');
src: url('font/aplayer-fontello.eot?72550380#iefix') format('embedded-opentype'),
url('font/aplayer-fontello.woff?72550380') format('woff'),
url('font/aplayer-fontello.ttf?72550380') format('truetype'),
url('font/aplayer-fontello.svg?72550380#fontello') format('svg');
font-weight: normal;
font-style: normal;
}
.aplayer-narrow {
width: $aplayer-height;
.aplayer-info {
@@ -50,53 +39,20 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
box-sizing: content-box;
}
[class^="aplayer-icon-"]:before, [class*=" aplayer-icon-"]:before {
font-family: "aplayer-fontello";
font-style: normal;
font-weight: normal;
display: inline-block;
text-decoration: inherit;
width: 1em;
text-align: center;
font-variant: normal;
text-transform: none;
line-height: 1em;
}
.aplayer-icon {
width: 15px;
height: 15px;
border: none;
background-color: transparent;
outline: none;
cursor: pointer;
opacity: .8;
vertical-align: middle;
padding: 0;
.aplayer-icon-play:before {
content: '\e806';
}
.aplayer-icon-pause:before {
content: '\e807';
}
.aplayer-icon-to-start:before {
content: '\e808';
}
.aplayer-icon-to-end:before {
content: '\e809';
}
.aplayer-icon-loop:before {
content: '\e803';
}
.aplayer-icon-menu:before {
content: '\e80b';
}
.aplayer-icon-volume-off:before {
content: '\e800';
}
.aplayer-icon-volume-down:before {
content: '\e801';
}
.aplayer-icon-volume-up:before {
content: '\e802';
.aplayer-fill {
transition: all .2s ease-in-out;
}
}
.aplayer-lrc-content {
@@ -114,7 +70,6 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-button {
position: absolute;
color: #fff;
border-radius: 50%;
opacity: 0.8;
cursor: pointer;
@@ -125,6 +80,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
&:hover {
opacity: 1;
}
.aplayer-fill {
fill: #fff;
}
}
.aplayer-hide {
@@ -140,10 +99,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
margin: 0 -15px -15px 0;
.aplayer-icon-play {
position: absolute;
top: 2px;
top: 3px;
left: 4px;
font-size: 20px;
line-height: 23px;
height: 20px;
width: 20px;
}
}
@@ -155,10 +114,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
right: 4px;
.aplayer-icon-pause {
position: absolute;
top: 1px;
top: 2px;
left: 2px;
font-size: 12px;
line-height: 14px;
height: 12px;
width: 12px;
}
}
}
@@ -173,7 +132,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: 17px;
margin-bottom: 13px;
.aplayer-title {
font-size: 14px;
@@ -190,13 +149,14 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-bar-wrap {
margin: 0 140px 0 5px;
padding: 4px 0;
cursor: pointer !important;
.aplayer-bar {
position: relative;
height: 2px;
width: 100%;
background: #cdcdcd;
cursor: pointer !important;
.aplayer-loaded {
position: absolute;
@@ -234,29 +194,41 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-time {
position: absolute;
right: 0;
bottom: -5px;
bottom: -3px;
height: 17px;
color: #999;
font-size: 11px;
i {
color: #666;
font-size: 15px;
.aplayer-time-inner {
vertical-align: middle;
}
.aplayer-icon {
cursor: pointer;
transition: all 0.2s ease;
.aplayer-fill {
fill: #666;
}
&.aplayer-icon-loop {
margin-right: 4px;
}
&.aplayer-noloop {
color: #ddd;
.aplayer-fill {
fill: #ddd;
}
&:hover {
color: #bbb;
.aplayer-fill {
fill: #bbb;
}
}
}
&:hover {
color: #000;
.aplayer-fill {
fill: #000;
}
}
}
@@ -284,8 +256,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
.aplayer-volume-bar-wrap {
display: none;
position: absolute;
bottom: 17px;
right: -5px;
bottom: 15px;
right: -3px;
width: 25px;
height: 40px;
z-index: 99;
@@ -373,12 +345,11 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
}
.aplayer-list {
max-height: 300px;
overflow: auto;
transition: all 0.5s ease;
&.aplayer-list-hide {
max-height: 0;
height: 0 !important;
}
ol {
@@ -395,6 +366,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
border-top: 1px solid #e9e9e9;
cursor: pointer;
transition: all 0.2s ease;
overflow: hidden;
&:hover {
background: #efefef;
Binary file not shown.
-20
View File
@@ -1,20 +0,0 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2016 by original authors @ fontello.com</metadata>
<defs>
<font id="fontello" horiz-adv-x="1000" >
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="volume-off" unicode="&#xe800;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z" horiz-adv-x="428.6" />
<glyph glyph-name="volume-down" unicode="&#xe801;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z m214-304q0-42-24-79t-63-52q-5-3-14-3-14 0-25 10t-10 26q0 12 6 20t17 14 19 12 16 20 6 32-6 32-16 20-19 12-17 14-6 20q0 15 10 26t25 10q9 0 14-3 39-15 63-52t24-79z" horiz-adv-x="642.9" />
<glyph glyph-name="volume-up" unicode="&#xe802;" d="m429 654v-608q0-14-11-25t-25-10-25 10l-186 186h-146q-15 0-25 11t-11 25v214q0 15 11 25t25 11h146l186 186q10 10 25 10t25-10 11-25z m214-304q0-42-24-79t-63-52q-5-3-14-3-14 0-25 10t-10 26q0 12 6 20t17 14 19 12 16 20 6 32-6 32-16 20-19 12-17 14-6 20q0 15 10 26t25 10q9 0 14-3 39-15 63-52t24-79z m143 0q0-85-48-158t-125-105q-8-3-14-3-15 0-26 11t-10 25q0 22 21 33 32 16 43 25 41 30 64 75t23 97-23 97-64 75q-11 9-43 25-21 11-21 33 0 14 10 25t25 11q7 0 15-3 78-33 125-105t48-158z m143 0q0-128-71-236t-189-158q-7-3-14-3-15 0-26 11t-10 25q0 20 22 33 4 2 12 6t13 6q25 14 45 28 69 51 108 127t38 161-38 161-108 127q-20 14-45 28-4 3-13 6t-12 6q-22 13-22 33 0 14 10 25t26 11q7 0 14-3 118-51 189-158t71-236z" horiz-adv-x="928.6" />
<glyph glyph-name="loop" unicode="&#xe803;" d="m800 540q42 0 71-29t29-71l0-290q0-40-29-70t-71-30l-700 0q-40 0-70 30t-30 70l0 290q0 42 30 71t70 29l250 0 0 110 200-180-200-180 0 110-210 0 0-210 620 0 0 210-150 0 0 140 190 0z" horiz-adv-x="900" />
<glyph glyph-name="play" unicode="&#xe806;" d="m486 376q14-10 14-26 0-14-14-24l-428-266q-24-16-41-6t-17 40l0 514q0 30 17 40t41-6z" horiz-adv-x="500" />
<glyph glyph-name="pause" unicode="&#xe807;" d="m440 700q90 0 90-64l0-570q0-66-90-66t-90 66l0 570q0 64 90 64z m-350 0q90 0 90-64l0-570q0-66-90-66t-90 66l0 570q0 64 90 64z" horiz-adv-x="530" />
<glyph glyph-name="to-start" unicode="&#xe808;" d="m174 350q0 14 14 24l364 228q20 14 34 5t14-35l0-442q0-26-14-35t-34 5l-364 228q-14 10-14 22z m-174 234q0 58 76 58 74 0 74-58l0-466q0-58-74-58-76 0-76 58l0 466z" horiz-adv-x="600" />
<glyph glyph-name="to-end" unicode="&#xe809;" d="m412 374q14-10 14-24 0-12-14-22l-362-228q-22-14-36-5t-14 35l0 442q0 26 14 35t36-5z m114 268q74 0 74-58l0-466q0-58-74-58-76 0-76 58l0 466q0 58 76 58z" horiz-adv-x="600" />
<glyph glyph-name="menu" unicode="&#xe80b;" d="m650 400q22 0 36-15t14-35-15-35-35-15l-600 0q-20 0-35 15t-15 35 14 35 36 15l600 0z m-600 100q-20 0-35 15t-15 35 14 35 36 15l600 0q22 0 36-15t14-35-15-35-35-15l-600 0z m600-300q22 0 36-15t14-35-15-35-35-15l-600 0q-20 0-35 15t-15 35 14 35 36 15l600 0z" horiz-adv-x="700" />
</font>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.
Binary file not shown.