-
Notifications
You must be signed in to change notification settings - Fork 203
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
Implement playCount database update #201
Implement playCount database update #201
Conversation
@@ -158,6 +159,14 @@ export default class PlayingBar extends Component { | |||
|
|||
tick() { | |||
this.setState({ elapsed: Player.getAudio().currentTime }); | |||
|
|||
if (!Player.isThresholdReached() && Player.getAudio().currentTime >= Player.getAudio().duration * Player.getThreshold()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get the purpose of the thresholdReached
variable and all associated infra.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't do that it will increment each tick() call when Player.getAudio().currentTime >= Player.getAudio().duration * Player.getThreshold()
so basically every 100 ms after the threshold.
Plus, this also prevent the incrementaion if the user scrolls back.
This is my very first pull request. Fell free to criticize me if I do wrong!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can move Player.getAudio().currentTime >= Player.getAudio().duration * Player.getThreshold()
into local variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even put this entire method out of component to lib/player.js
, cause it fits there better IMO.
Thanks for the PR, I'll review it a soon as I have some free time. I'll try to investigate why AppVeyor fails too. |
Ok, the threshold reached check condition should be in a single method. So we have So in // this function name is a bit misleading, any better idea ?
isThresholdReached() {
if(!this.tresholdReached && this.audio.currentTime >= this.audio.duration * this.threshold) {
this.thresholdReached = true;
return true;
}
return false;
} and in if(Player.isThresholdReached()) {
LibraryActions.incrementPlayCount(this.props.queue[this.props.queueCursor]._id);
} I wrote this code quickly, there may be some mistakes. There would be some variable names confusions though, you may need to choose more appropriate function or variable name to make it clear. Once done, It should be ok to merge the PR. |
Side effect in method that should return boolean value does not seem like a good thing. |
What do you suggest ? |
Well, let's at least separate them and move out of components. |
Maybe the attribute |
@cfollet I'd say we should mention that this is track duration threshold. |
@YurySolovyov |
Sounds good. |
@YurySolovyov Calling it trackDurationThreshold means this variable is a threshold. In fact it is not. |
just drop |
side consistency note:
This means we'll have to get rid of all |
it is about AudioContext #128 ? |
@cfollet I think it is about moving code of this PR out of component(s) to the audio-related place. |
@cfollet Yury is right. It was just to inform you about what the |
303c154
to
9cbbac7
Compare
I updated the PR |
minor typos: it's 'Threshold', and not 'Threshhold' ;) |
9cbbac7
to
cc131d4
Compare
I think it's ok now |
My only concern was what if |
Why not put it into |
@YurySolovyov Sounds great. |
@KeitIG why do we use custom timeout and not timeupdate event in the first place? |
@YurySolovyov you mean why there is a @cfollet timeupdate looks great if perfs keep being fine. |
I mean why do we need componentDidMount() {
this.timer = setInterval(this.tick, 100);
} |
Ah, got it.
Sounds good. |
We can, I've chosen 150 because the progress bar was more fluid that way. |
Maybe in another PR though. |
Let's not pollute this PR too much indeed 😝 |
cc131d4
to
7a6bb6d
Compare
7a6bb6d
to
e3491e9
Compare
@cfollet This looks almost perfect, but can you please move |
It's ok for me. I've made it that way so we now where this come from. This will have to move elsewhere anyway. |
Thanks for your work @cfollet ! |
Closes #160.