more player events

This commit is contained in:
DIYgod
2018-03-09 16:25:35 +08:00
parent fc1a04b303
commit 420c5db9f4
2 changed files with 7 additions and 1 deletions
+3 -1
View File
@@ -8,7 +8,9 @@ class Events {
'playing', 'progress', 'ratechange', 'seeked', 'seeking', 'stalled', 'suspend',
'timeupdate', 'volumechange', 'waiting'
];
this.playerEvents = [];
this.playerEvents = [
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
];
}
on (name, callback) {
+4
View File
@@ -183,6 +183,7 @@ class APlayer {
switchAudio (index) {
this.handlePlayPromise(() => {
this.events.trigger('switchaudio', index);
if (typeof index !== 'undefined') {
this.playIndex = index;
}
@@ -381,6 +382,7 @@ class APlayer {
* @param {Array} newMusic
*/
addAudio (newMusic) {
this.events.trigger('addaudio', newMusic);
const wasSingle = !this.isMultiple();
this.options.audio = this.options.audio.concat(newMusic);
@@ -411,6 +413,7 @@ class APlayer {
* Remove song from playlist
*/
removeAudio (index) {
this.events.trigger('removeaudio', index);
if (this.options.audio[index] && this.options.audio.length > 1) {
const list = this.container.querySelectorAll('.aplayer-list li');
@@ -448,6 +451,7 @@ class APlayer {
this.container.innerHTML = '';
this.audio.src = '';
this.timer.destroy();
this.events.trigger('destroy');
}
handlePlayPromise (callback) {