PDA

View Full Version : hit counter for streamed sound



aconeinc
December 30th, 2003, 04:13 PM
How can I make a visible hit counter for sound streams, not page hits? My sounds buttons currently use the mysound/loadsound action to stream external mp3. How can I make a visible counter to keep a tab of how many times music is streamed?

thanks in advance for your reply
ken

andr.in
December 30th, 2003, 05:03 PM
With what? asp? php? perl? ...etc?

aconeinc
December 30th, 2003, 06:21 PM
php is the only one i'm familiar with so I guess that

andr.in
December 31st, 2003, 02:32 AM
ok...It's just like every other counter: flash calls a php file which will open a txt file, increase the number in it and write it to the same file and if needed returns the number. The only difference is that the php needs to be called when the sound starts playing.



$count = file_get_contents("count.txt");
$count++;
$fp = fopen("count.txt", "w+");
fwrite($fp, $count);
fclose($fp);


Now you should make a text file named "count.txt" and type a number '0' in it (I'm not sure if this is necessary but just in case) and change it's permissions to 777 when you upload the file to your server.
Now in flash you need to trigger the php file once the sound starts loading.
So for the buttons that should load a sound add this action:


loadVariablesNum("counter.php", 0);

Just make sure that the file in the quotes is the php file...

PS! There should be a hit counter tute coming soon.

aconeinc
December 31st, 2003, 02:09 PM
I did everything you specified first to test it. I added the load variable code to my flash button, made a counter.php file and a count.txt file (with 0). But when I test it by uploading everything, opening a new browser and pressing play, I check back with my web admin and in the count.txt file, the value is still 0. I changed the permissiom too. What might be doing wrong?

In addition, I wanted that number to be visible on the page where users press play

take a look at this page and see where it says total plays, I am trying to make a visible counter right under it.

www.aconeinc.com/beats.htm

andr.in
December 31st, 2003, 06:13 PM
k... run the php file in your browser (on the server, not locally) and see if it gives you any error messages...

to see the count number in flash add this line at the end of your php file:

print "&count=".$count;

the variable name of your dynamic textbox here should be "count" (you can change it to whatever but make sure you change te php file too)

and now to make sure flash displays the count correctly make sure the paths are correct (loadVariablesNum action is in the same movieclip where your dynamic textfile is).

aconeinc
January 1st, 2004, 04:18 PM
Thanks for the help so far, however when I created a dynamic text and named it count on the page I want the count to show on, something shows but not the number. It actually shows ".$count; Try it out urself. just click the first sound "fresh" and you'll see what I mean up on the total plays section. Also when checking the count.txt file, it still says 0 regardless of how many times I've played. I'm not sure if the php script actually calls the count.txt. what say u?

www.aconeinc.com/beats.htm

eyezberg
January 1st, 2004, 08:32 PM
for later: once you get it working, you may want to randomize the load with an extra value (usually current timestamp) to avoid caching the sma $count value...

post your complete php script for debugging (in php tags pls)

andr.in
January 2nd, 2004, 03:05 AM
hm.... this is some strange fenomena..

Run the php file in your browser.. see if it returns any errors or something...
maybe you're using an oled version of php that doesn't support file_get_contents...

aconeinc
January 2nd, 2004, 12:29 PM
No errors just the code list horizontally. Say I'm using the old version, whats the alternative code to getting the content of a txt file if any. If not, do you know any other ways to get around this?

andr.in
January 2nd, 2004, 01:06 PM
if you have an older version then replace
file_get_contents("count.txt");

with



$file = fopen("count.txt", "r");
$count = fread($file, 1024);
fclose($file);

aconeinc
January 7th, 2004, 02:16 PM
I finally got it to work but it on that page, there are several sound buttons I applied the "loadVariablesNum("counter.php", 0);" action to. However, the counter seems to only record the first hit and doesn't account for subsequent hits on that page. Even when I run a new browser, still the counter doesn't update for other hits.

2. The counter seems to only show when a button is hit. how do I make it show when the page loads like conventional counters?

andr.in
January 7th, 2004, 02:44 PM
well then you gotta change the php and the text file a bit too...

in teh textfile put:
count=0



$file = fopen("count.txt", "r");
$count = fread($file, 1024);
fclose($file);
$count = explode("=", $count);
$count[1] = $count[1]+1;
$file = fopen("count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
print "count=".$count[1];


flash actions:

loadVariablesNum("count.txt", 0);

this mus tbe put somewhere in the beginning but it has to be in the same movieclip where your tesxtbox is (and the textbox must be on the stage in that frame).

aconeinc
January 7th, 2004, 03:00 PM
I'm sorry I should have told you, I made it work with the first tutorial you gave me. In order words I'm using the latest version of php. So if you could re-modify this old php code, i'd appreciate it. Thanks in advance

andr.in
January 8th, 2004, 03:59 AM
$count = file_get_contents("count.txt");
$count = explode("=", $count);
$count[1] = $count[1]+1;
$file = fopen("count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);
print "count=".$count[1];

aconeinc
January 8th, 2004, 11:13 AM
Thank you Syko, but for some reason, it still only accounts for the first sound hit. Any other sound hit is not recorded. Quite perplexing

andr.in
January 10th, 2004, 04:21 AM
try this instead:

loadVariablesNum("counter.php?num="+random(999), 0);

aconeinc
January 11th, 2004, 04:14 PM
Thanks Syko, it works just fine now. Really appreciate the help and patience. Thanks