corillo181 Posted February 17, 2008 Share Posted February 17, 2008 how can i count how many times a song is being heard? like when the person clicks on it is would be the same as when they try to download it but instead they are taken to a page where the song is play by their default player but be counted to the database as a +1 Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 17, 2008 Share Posted February 17, 2008 UPDATE songs SET hits = hits + 1 WHERE id = 5; Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 i know that part i mean the content that has to be sent as the heade in order to make the page read as a mp3 and not a normal text/html i'm now too good with header content but i know is something like header('content-type: mp3'); and then i do the query which is what you posted.. Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 17, 2008 Share Posted February 17, 2008 Something like this? <?php mysql_query("UPDATE songs SET hits = hits + 1 WHERE id = 5;"); header("Content-Type: audio/mpeg"); $mp3 = file_get_contents("the.mp3"); echo $mp3; ?> Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 that works but it plays 1 second of the song. i did this header("Content-Type: audio/mpeg"); $mp3 = file_get_contents('song/'.$song['song_path']); echo $mp3; Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 try readfile($mp3) instead of echo. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 no now i can't hear nothing at all. Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 Well this new security on the forums won't let me post this reply. I can email it if u want. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 ok send it to corillo181@yahoo.com Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 better yet, just look at it here. http://chrisdburns.com/reply.txt Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 that dont work only prompts to download the song. Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 I'm not too great with headers, I was hoping that would get somewhere. I'm assuming one of the headers is forcing the download. I wouldn't have a clue which one though. Quote Link to comment Share on other sites More sharing options...
hokietoner Posted February 17, 2008 Share Posted February 17, 2008 that dont work only prompts to download the song. If you set the headers like that and output the contents of the file, the browser is going to prompt you to do something based on the header. If it's an HTML file, the browser will open the file itself. But if it detects an mp3 file, it's going to prompt you to download it just as if you tried to browse to www.somesite.com/asong.mp3 Quote Link to comment Share on other sites More sharing options...
hokietoner Posted February 17, 2008 Share Posted February 17, 2008 As far as I know if you want to have a web page play an embedded mp3 you'll have to do some html magic. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 yeah but the first guy to help got to a point where i can listen to the song with out downloading, but it only plays a few seconds. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 17, 2008 Author Share Posted February 17, 2008 alright i got it to work... just needed to change the Content-Type: x-mp3 to audio/mpeg Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 17, 2008 Share Posted February 17, 2008 You probably just needed the content length.. but it all depends on what you are playing it with. I had no trouble using the embed tag, or a flash mp3 player. fclose($filename); thows a warning. Should be fclose($fh); Quote Link to comment Share on other sites More sharing options...
dave420 Posted February 18, 2008 Share Posted February 18, 2008 You should also remember the script will time out if it can't send the entire mp3 in 30 seconds (or whatever timeout you have set). Use set_time_limit() to override this. If you want to get fruity, look into accepting byte ranges in your headers, and how to interpret them and send their response-counterparts, which will allow MP3 players to seek/rewind/fast-forward in your streaming mp3s. It's not as tricky as it sounds, and is very useful. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.