Skip to content

Commit 420c5db

Browse files
committed
more player events
1 parent fc1a04b commit 420c5db

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/js/events.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class Events {
88
'playing', 'progress', 'ratechange', 'seeked', 'seeking', 'stalled', 'suspend',
99
'timeupdate', 'volumechange', 'waiting'
1010
];
11-
this.playerEvents = [];
11+
this.playerEvents = [
12+
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
13+
];
1214
}
1315

1416
on (name, callback) {

src/js/player.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class APlayer {
183183

184184
switchAudio (index) {
185185
this.handlePlayPromise(() => {
186+
this.events.trigger('switchaudio', index);
186187
if (typeof index !== 'undefined') {
187188
this.playIndex = index;
188189
}
@@ -381,6 +382,7 @@ class APlayer {
381382
* @param {Array} newMusic
382383
*/
383384
addAudio (newMusic) {
385+
this.events.trigger('addaudio', newMusic);
384386
const wasSingle = !this.isMultiple();
385387

386388
this.options.audio = this.options.audio.concat(newMusic);
@@ -411,6 +413,7 @@ class APlayer {
411413
* Remove song from playlist
412414
*/
413415
removeAudio (index) {
416+
this.events.trigger('removeaudio', index);
414417
if (this.options.audio[index] && this.options.audio.length > 1) {
415418
const list = this.container.querySelectorAll('.aplayer-list li');
416419

@@ -448,6 +451,7 @@ class APlayer {
448451
this.container.innerHTML = '';
449452
this.audio.src = '';
450453
this.timer.destroy();
454+
this.events.trigger('destroy');
451455
}
452456

453457
handlePlayPromise (callback) {

0 commit comments

Comments
 (0)