Skip to content

Commit

Permalink
[5.4.3] Optimization: giving a fake currentTime while sliding playing…
Browse files Browse the repository at this point in the history
… progress
  • Loading branch information
kirainmoe committed Sep 23, 2017
1 parent f82f505 commit 72f668e
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/assets/muse-player-preact.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assets/muse-player-react-lite.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assets/muse-player.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muse-player",
"version": "5.4.2",
"version": "5.4.3",
"description": "Just a simple and dilligent HTML5 Audio Player written in React.",
"main": "dist/assets/muse-player.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions src/components/Progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Progress extends Component {
};

id = undefined;
finalProgress = undefined;

constructor(props) {
super(props);
Expand Down Expand Up @@ -56,9 +57,13 @@ class Progress extends Component {
const rect = getRect(this.progress),
target = event.clientX,
width = this.progress.offsetWidth;
this.props.store.slideProgress(Number((target - rect.left) / width * duration));

this.finalProgress = Math.max(Number((target - rect.left) / width * duration), 0);
this.props.store.slideTimeOnly(this.finalProgress);
};
onHandlerMouseUp = () => {
this.props.store.slideProgress(this.finalProgress);

document.body.removeEventListener('mousemove', this.onHandlerDrag);
document.body.removeEventListener('mouseup', this.onHandlerMouseUp);
};
Expand All @@ -72,9 +77,12 @@ class Progress extends Component {
const rect = getRect(this.progress),
target = event.touches[0].clientX,
width = this.progress.offsetWidth;
this.props.store.slideProgress(Number((target - rect.left) / width * duration));

this.finalProgress = Math.max(Number((target - rect.left) / width * duration), 0);
this.props.store.slideTimeOnly(this.finalProgress);
};
onHandlerTouchEnd = () => {
this.props.store.slideProgress(this.finalProgress);
document.body.removeEventListener('touchmove', this.onHandlerTouchMove);
document.body.removeEventListener('touchend', this.onHandlerMouseUp);
};
Expand Down
2 changes: 1 addition & 1 deletion src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// Settings configured here will be merged into the final config object.
export default {
MUSE_VERSION: '5.4.2'
MUSE_VERSION: '5.4.3'
}
16 changes: 14 additions & 2 deletions src/containers/ControlContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default class ControlContainer extends Component {

/* store subscribers */
subscriber = () => {
const { store } = this.props,
const { store, parent } = this.props,
{ audio } = this,
{ currentTime, volume, playRate } = store;
{ currentTime, timeSlider, volume, playRate } = store;
// toggle play
if (!audio.paused != store.isPlaying) {
if (store.isPlaying) {
Expand All @@ -35,9 +35,21 @@ export default class ControlContainer extends Component {
return;
}
// slide progress
if (timeSlider != undefined) {
// remove listener
this.audio.removeEventListener('timeupdate', this.onAudioTimeUpdate);
// update parent state with a virtual ptime
parent.setState({
...parent.state,
currentTime: timeSlider
});
store.slideTimeOnly(undefined);
}
if (currentTime != undefined) {
audio.currentTime = currentTime;
store.slideProgress(undefined); // reset state
// rebind listener
this.audio.addEventListener('timeupdate', this.onAudioTimeUpdate);
}
// change volume
audio.volume = volume;
Expand Down
2 changes: 1 addition & 1 deletion src/example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/models/PlayerModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class PlayerModel {
@observable playRate = 1;
@observable duration = undefined;
@observable currentTime = 0;
@observable timeSlider = undefined;
@observable currentPanel = 'lyric';

@observable currentMusicIndex = 0;
Expand Down Expand Up @@ -109,6 +110,11 @@ export default class PlayerModel {
return (this.currentTime = progress);
}

@action
slideTimeOnly(progress) {
return (this.timeSlider = progress);
}

@action
setCurrentMusic(index) {
this.currentMusicIndex = index;
Expand Down
5 changes: 2 additions & 3 deletions src/styles/default.styl
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ Y8P 888 888 888 "Y88888 88888P' "Y8888 88888P" 888 "Y88P" "Y
height: 100%;
background: rgb(138, 194, 73);
position: relative;

transition(.1s all ease-in-out);
transition(.1s all);
}

.muse-progress__handle {
Expand Down Expand Up @@ -333,7 +332,7 @@ Y8P 888 888 888 "Y88888 88888P' "Y8888 "Y88888 888 "Y888888 "Y
text-align: center;

.muse-drawer__lyric-container {
transition(.5s all ease-in-out);
transition(.5s all linear);
}

li {
Expand Down

0 comments on commit 72f668e

Please sign in to comment.