Skip to content

Commit 12fc049

Browse files
committed
new option: preload
1 parent c5776b2 commit 12fc049

5 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var option = {
5858
mutex: true, // Optional, pause other players when this player playing
5959
theme: '#e6d0b2', // Optional, theme color, default: #b7daff
6060
loop: true, // Optional, loop play music, default: true
61+
preload: 'metadata', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'metadata' in Desktop, 'none' in mobile
6162
music: { // Required, music info, see: ###With playlist
6263
title: 'Preparation', // Required, music title
6364
author: 'Hans Zimmer/Richard Harvey', // Required, music author

demo/demo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var ap1 = new APlayer({
55
showlrc: false,
66
mutex: true,
77
theme: '#e6d0b2',
8+
preload: 'metadata',
89
music: {
910
title: 'Preparation',
1011
author: 'Hans Zimmer/Richard Harvey',

dist/APlayer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/APlayer.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/APlayer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,12 @@
455455
if ((this.multiple && !this.audios[indexMusic]) || this.playIndex === -1) {
456456
this.audio = document.createElement("audio");
457457
this.audio.src = this.music.url;
458-
this.audio.preload = this.isMobile ? 'none' : 'metadata';
458+
if (this.option.preload) {
459+
this.audio.preload = this.option.preload;
460+
}
461+
else {
462+
this.audio.preload = this.isMobile ? 'none' : 'metadata';
463+
}
459464

460465
// show audio time: the metadata has loaded or changed
461466
this.audio.addEventListener('durationchange', () => {

0 commit comments

Comments
 (0)