new api: notice
This commit is contained in:
+24
-1
@@ -11,6 +11,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
line-height: initial;
|
||||
position: relative;
|
||||
|
||||
* {
|
||||
box-sizing: content-box;
|
||||
@@ -62,7 +63,8 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
.aplayer-list {
|
||||
display: none;
|
||||
}
|
||||
.aplayer-pic {
|
||||
.aplayer-pic,
|
||||
.aplayer-body {
|
||||
height: $aplayer-height;
|
||||
width: $aplayer-height;
|
||||
}
|
||||
@@ -91,6 +93,10 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-body {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.aplayer-icon {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
@@ -510,6 +516,23 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-notice {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 12px;
|
||||
border-radius: 4px;
|
||||
padding: 5px 10px;
|
||||
transition: all .3s ease-in-out;
|
||||
overflow: hidden;
|
||||
color: #fff;
|
||||
pointer-events: none;
|
||||
background-color: #f4f4f5;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes aplayer-roll {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ class Events {
|
||||
'timeupdate', 'volumechange', 'waiting'
|
||||
];
|
||||
this.playerEvents = [
|
||||
'destroy', 'switchaudio', 'addaudio', 'removeaudio'
|
||||
'destroy', 'switchaudio', 'addaudio', 'removeaudio', 'notice_show', 'notice_hide'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+16
-1
@@ -148,7 +148,7 @@ class APlayer {
|
||||
|
||||
// audio download error: an error occurs
|
||||
this.on('error', () => {
|
||||
this.template.author.innerHTML = ` - Error happens ╥﹏╥`;
|
||||
this.notice('An audio error has occurred.', 0);
|
||||
});
|
||||
|
||||
// multiple audio play
|
||||
@@ -488,6 +488,21 @@ class APlayer {
|
||||
}
|
||||
}
|
||||
|
||||
notice (text, time = 2000, opacity = 0.8) {
|
||||
this.template.notice.innerHTML = text;
|
||||
this.template.notice.style.opacity = opacity;
|
||||
if (this.noticeTime) {
|
||||
clearTimeout(this.noticeTime);
|
||||
}
|
||||
this.events.trigger('notice_show', text);
|
||||
if (time) {
|
||||
this.noticeTime = setTimeout(() => {
|
||||
this.template.notice.style.opacity = 0;
|
||||
this.events.trigger('notice_hide');
|
||||
}, time);
|
||||
}
|
||||
}
|
||||
|
||||
handlePlayPromise (callback) {
|
||||
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
|
||||
console.error(err);
|
||||
|
||||
@@ -47,6 +47,7 @@ class Template {
|
||||
this.title = this.container.querySelector('.aplayer-title');
|
||||
this.author = this.container.querySelector('.aplayer-author');
|
||||
this.dtime = this.container.querySelector('.aplayer-dtime');
|
||||
this.notice = this.container.querySelector('.aplayer-notice');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+45
-42
@@ -1,52 +1,55 @@
|
||||
<div class="aplayer-pic" style="{{ if cover }}background-image: url("{{ cover }}");{{ /if }}background-color: {{ options.theme }};">
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</div>
|
||||
<div class="aplayer-info">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title"></span>
|
||||
<span class="aplayer-author"></span>
|
||||
<div class="aplayer-body">
|
||||
<div class="aplayer-pic" style="{{ if cover }}background-image: url("{{ cover }}");{{ /if }}background-color: {{ options.theme }};">
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</div>
|
||||
<div class="aplayer-lrc">
|
||||
<div class="aplayer-lrc-contents" style="transform: translateY(0); -webkit-transform: translateY(0);"></div>
|
||||
</div>
|
||||
<div class="aplayer-controller">
|
||||
<div class="aplayer-bar-wrap">
|
||||
<div class="aplayer-bar">
|
||||
<div class="aplayer-loaded" style="width: 0"></div>
|
||||
<div class="aplayer-played" style="width: 0; background: {{ options.theme }};">
|
||||
<span class="aplayer-thumb" style="background: {{ options.theme }};">
|
||||
<span class="aplayer-loading-icon">{{@ icons.loading }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-info">
|
||||
<div class="aplayer-music">
|
||||
<span class="aplayer-title"></span>
|
||||
<span class="aplayer-author"></span>
|
||||
</div>
|
||||
<div class="aplayer-time">
|
||||
<span class="aplayer-time-inner">
|
||||
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||
</span>
|
||||
<div class="aplayer-volume-wrap">
|
||||
<button type="button" class="aplayer-icon aplayer-icon-volume-down">
|
||||
{{@ icons.volumeDown }}
|
||||
</button>
|
||||
<div class="aplayer-volume-bar-wrap">
|
||||
<div class="aplayer-volume-bar">
|
||||
<div class="aplayer-volume" style="height: 80%; background: {{ options.theme }};"></div>
|
||||
<div class="aplayer-lrc">
|
||||
<div class="aplayer-lrc-contents" style="transform: translateY(0); -webkit-transform: translateY(0);"></div>
|
||||
</div>
|
||||
<div class="aplayer-controller">
|
||||
<div class="aplayer-bar-wrap">
|
||||
<div class="aplayer-bar">
|
||||
<div class="aplayer-loaded" style="width: 0"></div>
|
||||
<div class="aplayer-played" style="width: 0; background: {{ options.theme }};">
|
||||
<span class="aplayer-thumb" style="background: {{ options.theme }};">
|
||||
<span class="aplayer-loading-icon">{{@ icons.loading }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ if options.audio.length > 1 }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
{{ /if }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-loop">
|
||||
{{ if options.loop === 'one' }}{{@ icons.loopOne }}{{ else if options.loop === 'all' }}{{@ icons.loopAll }}{{ else if options.loop === 'none' }}{{@ icons.loopNone }}{{ /if }}
|
||||
</button>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-menu">
|
||||
{{@ icons.menu }}
|
||||
</button>
|
||||
<div class="aplayer-time">
|
||||
<span class="aplayer-time-inner">
|
||||
- <span class="aplayer-ptime">00:00</span> / <span class="aplayer-dtime">00:00</span>
|
||||
</span>
|
||||
<div class="aplayer-volume-wrap">
|
||||
<button type="button" class="aplayer-icon aplayer-icon-volume-down">
|
||||
{{@ icons.volumeDown }}
|
||||
</button>
|
||||
<div class="aplayer-volume-bar-wrap">
|
||||
<div class="aplayer-volume-bar">
|
||||
<div class="aplayer-volume" style="height: 80%; background: {{ options.theme }};"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ if options.audio.length > 1 }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
{{ /if }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-loop">
|
||||
{{ if options.loop === 'one' }}{{@ icons.loopOne }}{{ else if options.loop === 'all' }}{{@ icons.loopAll }}{{ else if options.loop === 'none' }}{{@ icons.loopNone }}{{ /if }}
|
||||
</button>
|
||||
<button type="button" class="aplayer-icon aplayer-icon-menu">
|
||||
{{@ icons.menu }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="aplayer-notice"></div>
|
||||
</div>
|
||||
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
|
||||
Reference in New Issue
Block a user