18 Commits
Author SHA1 Message Date
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
6 changed files with 88 additions and 57 deletions
+8 -4
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
@@ -190,9 +192,11 @@ $ 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
+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
@@ -1,6 +1,6 @@
{
"name": "aplayer",
"version": "1.4.2",
"version": "1.4.6",
"description": "Wow, such a beautiful html5 music player",
"main": "dist/APlayer.min.js",
"scripts": {
+58 -32
View File
@@ -1,5 +1,4 @@
(() => {
let APlayers = [];
((instances) => {
class APlayer {
/**
@@ -23,7 +22,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 +36,7 @@
this.option = option;
this.audios = [];
this.loop = true;
this.loop = option.loop;
/**
* Parse second to 00:00 format
@@ -127,12 +127,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,7 +175,7 @@
// 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(${encodeURI(this.music.pic)});"`) : ``)}>
<div class="aplayer-button aplayer-play">
<i class="demo-icon aplayer-icon-play"></i>
</div>
@@ -207,7 +207,7 @@
</div>
</div>
</div>
<i class="demo-icon aplayer-icon-loop"></i>${(this.multiple ? `<i class="demo-icon aplayer-icon-menu"></i>` : ``)}
<i class="demo-icon aplayer-icon-loop${(this.loop ? `` : ` aplayer-noloop`)}"></i>${(this.multiple ? `<i class="demo-icon aplayer-icon-menu"></i>` : ``)}
</div>
</div>
</div>`;
@@ -230,6 +230,8 @@
}
this.element.innerHTML = eleHTML;
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');
}
@@ -261,7 +263,12 @@
if (musicIndex !== this.playIndex) {
this.setMusic(musicIndex);
}
this.play();
if (this.isMobile) {
this.pause();
}
else {
this.play();
}
});
}
}
@@ -304,7 +311,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', () => {
@@ -404,8 +418,8 @@
this.setMusic(0);
APlayers.push(this);
};
instances.push(this);
}
/**
* Set music
@@ -441,7 +455,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 +490,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,7 +567,7 @@
if (this.isMobile) {
this.pause();
}
};
}
/**
* Play music
@@ -557,9 +583,9 @@
// 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 +598,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
@@ -595,7 +621,7 @@
clearInterval(this.playedTime);
this.trigger('pause');
}
};
}
/**
* attach event
@@ -608,9 +634,9 @@
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = APlayer
module.exports = APlayer;
}
else {
window.APlayer = APlayer;
}
})();
})([]);