Skip to content

Commit

Permalink
time module; some optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Mar 1, 2018
1 parent 5905d0e commit c9e7f8a
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 178 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
},
"dependencies": {
"balloon-css": "^0.5.0",
"promise-polyfill": "7.0.2"
"promise-polyfill": "7.1.0"
}
}
4 changes: 2 additions & 2 deletions src/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
bottom: 50%;
right: 50%;
margin: 0 -15px -15px 0;
.aplayer-icon-play {
svg {
position: absolute;
top: 3px;
left: 4px;
Expand All @@ -161,7 +161,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
border: 2px solid #fff;
bottom: 4px;
right: 4px;
.aplayer-icon-pause {
svg {
position: absolute;
top: 2px;
left: 2px;
Expand Down
17 changes: 5 additions & 12 deletions src/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class Controller {
this.player.bar.set('played', 0, 'width');
}
else {
this.player.bar.set('played', percentage, 'width');
this.player.template.ptime.innerHTML = utils.secondToTime(percentage * this.player.audio.duration);
this.player.audio.currentTime = this.player.bar.get('played', 'width') * this.player.audio.duration;
this.player.seek(percentage * this.player.audio.duration);
}
});

Expand All @@ -70,7 +68,7 @@ class Controller {
percentage = percentage > 0 ? percentage : 0;
percentage = percentage < 1 ? percentage : 1;
this.player.bar.set('played', percentage, 'width');
this.player.lrc && this.player.lrc.update(this.player.bar.get('played', 'width') * this.player.audio.duration);
this.player.lrc && this.player.lrc.update(percentage * this.player.audio.duration);
this.player.template.ptime.innerHTML = utils.secondToTime(percentage * this.player.audio.duration);
};

Expand All @@ -81,19 +79,14 @@ class Controller {
this.player.bar.set('played', 0, 'width');
}
else {
this.player.audio.currentTime = this.player.bar.get('played', 'width') * this.player.audio.duration;
this.player.playedTime = setInterval(() => {
this.player.bar.set('played', this.player.audio.currentTime / this.player.audio.duration, 'width');
this.player.lrc && this.player.lrc.update();
this.player.template.ptime.innerHTML = utils.secondToTime(this.player.audio.currentTime);
this.player.trigger('playing');
}, 100);
this.player.seek(this.player.bar.get('played', 'width') * this.player.audio.duration);
this.player.timer.enable('progress');
}
};

this.player.template.thumb.addEventListener('mousedown', () => {
barWidth = this.player.template.barWrap.clientWidth;
clearInterval(this.player.playedTime);
this.player.timer.disable('progress');
document.addEventListener('mousemove', thumbMove);
document.addEventListener('mouseup', thumbUp);
});
Expand Down
Loading

0 comments on commit c9e7f8a

Please sign in to comment.