Jump to content

Strange If Behavior


chasethemetal

Recommended Posts

Hey all. So I have a media player... And I am trying to log information in a database about the percent played. For starters this one... percentPlayed == "1" logs that media was started. But for some reason or another it logs between 7-11 entries per time!? It is behaving as if percentPlayed equals 1, 7 to 11 times in a fraction of a second... Also I have php adding a record like so... count=count+1, so I don't think its an issue there. Any thoughts? Is there a way to add .load_once haha? Anyways, any help is always appreciated. (i have verified that this var outputs a percent count up accurately) var percentPlayed = parseInt(event.player.status.currentPercentAbsolute, 10); if (percentPlayed == "1"){ var name = $.trim($(my_name).text().substr(10).replace(/ /g,'%20'));$("#name").load('handle.php?name='+trackName);}

Link to comment
Share on other sites

Update: So when I remove the parseInt() I notice it is actually counting the percentage like so 1.2343454345656677 incrementally up... This is accounting for the random 7 to 11 entries in my database, because percentPlayed is equal to one as it incrementally creeps up until it passes that 2.00... threshold. Now I thought I could just do this percentPlayed == "1.0000000000000000" right? But it's chance that the percent would land EXACTLY on 1.0000000000000000. Is there anyway to make this only happen once? Is this just an inherent problem with the media players counting?

Link to comment
Share on other sites

you could always try flooring and truncating the decimal output of percentPlayed, and then you can check it against 1 (or some other meaningful integer).

Link to comment
Share on other sites

I'm pretty sure the parseInt() was truncating the number. But it didn't work because it would basically fire off a 1 for every internal increment the code made until it hid 2 or greater and so on. BUT I found a solution by the way. The media player API comes with an inspector.js file as well, after digging through that I found that it displayed percent played as well but it was written out differently. I'm not sure why this works. But it does. Im not sure what flooring means, is this what the Math.floor below is doing? var percentPlayed = Math.floor(event.player.status.currentPercentAbsolute*10)/10;if (percentPlayed == "1") {do something}and so on.It works. And only fires the event onces.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...