new option: preload

This commit is contained in:
DIYgod 2016-06-13 14:23:51 +08:00
parent c5776b2a78
commit 12fc04957d
No known key found for this signature in database
GPG Key ID: F8797DD1088C6506
5 changed files with 10 additions and 3 deletions

View File

@ -58,6 +58,7 @@ var option = {
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

View File

@ -5,6 +5,7 @@ var ap1 = new APlayer({
showlrc: false,
mutex: true,
theme: '#e6d0b2',
preload: 'metadata',
music: {
title: 'Preparation',
author: 'Hans Zimmer/Richard Harvey',

2
dist/APlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -455,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', () => {