New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Custom Error Message Option #187

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@MPierre9
Member

MPierre9 commented Jan 25, 2018

Addresses issue #128 and adds the option for custom error messages.

Usage

Simply add the error property to the APlayer object and add your custom error message like so:
const ap1 = new APlayer({
element: document.getElementById('player1'),
narrow: false,
autoplay: true,
showlrc: false,
mutex: true,
theme: '#e6d0b2',
preload: 'metadata',
mode: 'circulation',
error: "Error: Song could not load", <=====
music: {
title: 'Preparation',
author: 'Hans Zimmer/Richard Harvey',
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
}
});

Result

aplayer error

@MPierre9

This comment has been minimized.

Member

MPierre9 commented Feb 1, 2018

@DIYgod does this PR need changes or is it good for merge?

@@ -558,7 +560,7 @@ class APlayer {
// audio download error: an error occurs
this.audio.addEventListener('error', () => {
this.element.getElementsByClassName('aplayer-author')[0].innerHTML = ` - Error happens ╥﹏╥`;
this.element.getElementsByClassName('aplayer-author')[0].innerHTML = ` - ` + this.option.error;

This comment has been minimized.

@micooz

micooz Feb 2, 2018

Member

Maybe need to prevent XSS attack here?

@DIYgod

This comment has been minimized.

Member

DIYgod commented Feb 2, 2018

I don't want this option, maybe expose an error event to user is a better way, usage is like this:

ap.on('error', function () {
    ap.notice('Error message');
});

@DIYgod DIYgod closed this Feb 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment