Skip to content
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

Merged

Conversation

cfollet
Copy link
Contributor

@cfollet cfollet commented Sep 11, 2016

Closes #160.

@cfollet cfollet changed the title Provides a playCount feature. Closes #160 Provides a playCount feature. Sep 11, 2016
@@ -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()) {
Copy link
Collaborator

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.

Copy link
Contributor Author

@cfollet cfollet Sep 11, 2016

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!

Copy link
Collaborator

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?

Copy link
Collaborator

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.

@martpie
Copy link
Owner

martpie commented Sep 11, 2016

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.

@martpie
Copy link
Owner

martpie commented Sep 12, 2016

Ok, the threshold reached check condition should be in a single method. So we have isThresholdReached that check if the action should be called, and move the check in Player.js indeed.

So in Player.js, we have:

// 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 PlayingBar.react.js

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.

@martpie martpie changed the title Provides a playCount feature. Implement playCount database update Sep 12, 2016
@YurySolovyov
Copy link
Collaborator

if(!this.tresholdReached && this.audio.currentTime >= this.audio.duration * this.threshold) {
    this.thresholdReached = true;
    return true;
}

Side effect in method that should return boolean value does not seem like a good thing.

@martpie
Copy link
Owner

martpie commented Sep 12, 2016

What do you suggest ?

@YurySolovyov
Copy link
Collaborator

Well, let's at least separate them and move out of components.

@cfollet
Copy link
Contributor Author

cfollet commented Sep 12, 2016

There would be some variable names confusions though, you may need to choose more appropriate function or variable name to make it clear.

Maybe the attribute this.thresholdReached can bethis.thresholdReachedFlag

@YurySolovyov
Copy link
Collaborator

@cfollet I'd say we should mention that this is track duration threshold.

@cfollet
Copy link
Contributor Author

cfollet commented Sep 12, 2016

@YurySolovyov thresholdReached to trackDurationThreshold ??

@YurySolovyov
Copy link
Collaborator

Sounds good.

@cfollet
Copy link
Contributor Author

cfollet commented Sep 12, 2016

@YurySolovyov Calling it trackDurationThreshold means this variable is a threshold. In fact it is not.
It's a boolean value that flag when the threshold is reached.
The name trackDurationThreshold would fit for the value this.audio.duration * this.threshold. But we are a little pernickety here :)

@YurySolovyov
Copy link
Collaborator

just drop track part, durationTreshholdReached. It is player, so it is mostly about tracks anyway :)

@martpie
Copy link
Owner

martpie commented Sep 12, 2016

side consistency note:

Player.js is meanly meant for audio manipulation, it is the interface between the audio system (Audio object for now) and the app. So we can easily switch to another system later if needed (WebAudio for example), without having to rewrite components.

This means we'll have to get rid of all Player.getAudio() one day to make things cleaner.

@cfollet
Copy link
Contributor Author

cfollet commented Sep 12, 2016

it is about AudioContext #128 ?

@YurySolovyov
Copy link
Collaborator

@cfollet I think it is about moving code of this PR out of component(s) to the audio-related place.

@martpie
Copy link
Owner

martpie commented Sep 12, 2016

@cfollet Yury is right. It was just to inform you about what the Player class is meant to be :) but this does not change anything about the changes required for this PR ;)

@cfollet cfollet force-pushed the implement-track-playCount-incrementation branch 2 times, most recently from 303c154 to 9cbbac7 Compare September 12, 2016 17:14
@cfollet
Copy link
Contributor Author

cfollet commented Sep 12, 2016

I updated the PR

@martpie
Copy link
Owner

martpie commented Sep 12, 2016

minor typos: it's 'Threshold', and not 'Threshhold' ;)

@cfollet cfollet force-pushed the implement-track-playCount-incrementation branch from 9cbbac7 to cc131d4 Compare September 12, 2016 19:42
@cfollet
Copy link
Contributor Author

cfollet commented Sep 13, 2016

I think it's ok now

@martpie
Copy link
Owner

martpie commented Sep 13, 2016

My only concern was what if state.repeat === 'one', but it seems like the threshold is reset anyway when AppActions.player.previous or AppActions.player.next are called. Seems good to me, any last thoughts @YurySolovyov ?

@YurySolovyov
Copy link
Collaborator

YurySolovyov commented Sep 13, 2016

Why not put it into timeupdate event handler? It would be a bit more efficient and we can extract the code from components entirely.

@cfollet
Copy link
Contributor Author

cfollet commented Sep 13, 2016

@YurySolovyov Sounds great.

@YurySolovyov
Copy link
Collaborator

@KeitIG why do we use custom timeout and not timeupdate event in the first place?

@martpie
Copy link
Owner

martpie commented Sep 13, 2016

@YurySolovyov you mean why there is a this.state.elapsed ?

@cfollet timeupdate looks great if perfs keep being fine.
If so, add your event there: AppActions.js:36.

@YurySolovyov
Copy link
Collaborator

I mean why do we need

componentDidMount() {
  this.timer = setInterval(this.tick, 100);
}

@martpie
Copy link
Owner

martpie commented Sep 13, 2016

For this and components perfs reason.

screenshot from 2016-09-13 11 10 08

Do you have a better idea ?

edit: it could be paused when there's no track playing.
re-edit: let's talk about that on Gitter

@YurySolovyov
Copy link
Collaborator

Ah, got it.

it could be paused when there's no track playing.

Sounds good.
Also, maybe increase timeout a bit? Say, 250 ms -> 4 times per second.

@martpie
Copy link
Owner

martpie commented Sep 13, 2016

We can, I've chosen 150 because the progress bar was more fluid that way.

@YurySolovyov
Copy link
Collaborator

Maybe in another PR though.

@martpie
Copy link
Owner

martpie commented Sep 13, 2016

Let's not pollute this PR too much indeed 😝

@cfollet cfollet force-pushed the implement-track-playCount-incrementation branch from cc131d4 to 7a6bb6d Compare September 14, 2016 18:51
@cfollet cfollet force-pushed the implement-track-playCount-incrementation branch from 7a6bb6d to e3491e9 Compare September 14, 2016 19:01
@YurySolovyov
Copy link
Collaborator

@cfollet This looks almost perfect, but can you please move Player.getAudio() calls to local variable? Should've done it earlier myself

@martpie
Copy link
Owner

martpie commented Sep 14, 2016

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.

@martpie martpie merged commit 3d248c7 into martpie:master Sep 14, 2016
@martpie
Copy link
Owner

martpie commented Sep 14, 2016

Thanks for your work @cfollet !

@cfollet cfollet deleted the implement-track-playCount-incrementation branch September 15, 2016 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants