Guide: WMP9 Now Playing

NetRyder

Tech Junkie
Joined
19 Apr 2002
Messages
13,256
Now Playing Script for Windows Media Player 9
This is a text-based version for use on your own webpage. An image-based version for use on forums etc. will follow later.
(Last Updated: Sept. 18, 2003)

1. Download the ZIP file attached to the next post, and run the setup file. This will install the Songwriter plugin to the WMP9 plugins folder (C:\Program Files\Windows Media Player\plugins\)

2. Open WMP9 and click Tools>Options. Switch to the "Plugins" tab, and select Background from the plugins list. Make sure "Songwriter Plugin" is checked.

3. Select the "Songwriter Plugin" and click Properties. You should see a dialog box that looks like the one in the attached image. Enter the details as shown in the image.

attachment.php

(This tutorial only covers the Artist and Title, so check only those two boxes. The code below can be modified to incorporate other details as well). Click OK and close WMP9.

4. Copy and paste the following code into a text editor, and save the file as nowplaying.php (No changes are required to the code)

nowplaying.php
Code:
<?php
   $songfilename = 'songout.txt';

   $songfile = fopen($songfilename, "r");
   $artist = trim(fgets($songfile));
   $song = trim(fgets($songfile));
   fclose($songfile);

   $last_update = date ("U", filemtime('songout.txt'));

   /* This check prevents junk characters from printing 
    * when the stop button is pressed due to a bug in SongWriter */
   if(strstr($artist,"+")) 
    print "No music playing";
   else {
     // No music playing if no updates in the last 10 minutes
     if($last_update < time()-600) 
      print "No music playing";
     else
      print $artist." - ".$song;
   }
?>

5. Upload nowplaying.php to the same folder as the one you entered in the SongWriter config dialog box.

6. Now fire up WMP9, and play your favorite tune. The file songout.txt will automatically be updated with the song details. You can now use the include() function to display the currently playing song anywhere on your webpage. For example:

index.php
Code:
<html>
<head><title>Test Page</title></head>
<body>
Page Content Page Content Page Content Page Content Page Content Page Content
Page Content Page Content Page Content Page Content Page Content Page Content 
Page Content Page Content Page Content Page Content Page Content Page Content

<br />
Now Playing: <?php include('nowplaying.php'); ?>
<br />

Page Content Page Content Page Content Page Content Page Content Page Content
Page Content Page Content Page Content Page Content Page Content Page Content 
Page Content Page Content Page Content Page Content Page Content Page Content
</body>
</html>
 
Here is the SongWriter plugin for WMP9:
(Updated Sept 18 - Now contains an installer file)
 
This could be used with the Winamp now playing script to generate the picture i have in my sig.
 
This is an image-based version for use on your website or forums
(Last Updated: Sept. 17, 2003)

First, follow steps 1 to 3 from the first post in this thread.

4. Copy and paste the following code into a text editor, and save the file as nowplayingimg.php (No changes are required to the code)

nowplayingimg.php
Code:
<?php
   $songfilename = 'songout.txt';

   $songfile = fopen($songfilename, "r");
   $artist = trim(fgets($songfile));
   $song = trim(fgets($songfile));
   fclose($songfile);

   $last_update = date ("U", filemtime('songout.txt'));

   /* This check prevents junk characters from printing 
    * when the stop button is pressed due to a bug in SongWriter */
   if(strstr($artist,"+")) 
    $txtsong = "No music playing";
   else {
    if($last_update < time()-600)
     $txtsong = "No music playing";
    else
     $txtsong = $artist." - ".$song;
   }

   // Thanks to SPeedY_B for the code used below.
   $font = 2;
   $imgw = ImageFontWidth($font) * strlen($txtsong) + (10* ImageFontWidth($font));

   if (strlen($txtsong) > 45) {
    $txtsong = substr($txtsong, 0, 43)."..";
    $imgw  = ImageFontWidth($font) * strlen($txtsong) + (10* ImageFontWidth($font));
   }

   $imgb = ($imgw -1);
   Header("Content-Type: image/png");
   $im = ImageCreate($imgw, 15);
   $bgc = ImageColorAllocate($im, 255, 255, 255);
   $black = ImageColorAllocate($im, 0, 0, 0);
   ImageFill($im, 0, 0, $bgc);
   ImageString($im, $font, 3, 0, "WMP9 : $txtsong", $black);
   ImageLine($im, 0, 0, 0, 14, $black);
   ImageLine($im, 0, 0, $imgb, 0, $black);
   ImageLine($im, $imgb, 0, $imgb, 14, $black);
   ImageLine($im, 0, 14, $imgb, 14, $black);
   Imagepng($im);
?>

5. Upload nowplaying.php to the same folder as the one you entered in the SongWriter config dialog box.

6. Now fire up WMP9, and play your favorite tune. The file songout.txt will automatically be updated with the song details. You can now link to nowplayingimg.php to display an image on your site, or on a forum. For example,

Forum signature:
Code:
[img ]http://www.path_to_site.com/nowplayingimg.php[/img ]
 
If using Apache, create a .htaccess like this:

Code:
<Files playing.png>
ForceType application/x-httpd-php
</Files>

Then rename the above nowplayingimg.php to playing.png, now you can link to it even on forums where dynamic images are not allowed in the signature.
 
Thanks NetRyder! I have been waiting to find something like this. :)
 
Glad it was useful :)
@X-Istence: Thanks for the .htaccess PNG-addon. That looks interesting ;)
 
Code Updated

* Now uses the trim() function to correct a line-break bug

* If songout.txt is not modified for 10 minutes, it's assumed that no music is playing. This timeout can be increased or decreased by changing the 600 seconds in the line:
Code:
if($last_update < time()-600)
 
Originally posted by NetRyder
Glad it was useful :)
@X-Istence: Thanks for the .htaccess PNG-addon. That looks interesting ;)

My pleasure, makes it easier to bypass the "no dynamic signatures" that some boards have, and considering it doesnt have any performance loss, why not :).
 
I'm having problems. I'm playing a song right now, but I don't get it displayed in my sig.
 
If you FTP into your server, can you see a file called songout.txt?
If so, download it and check it's contents.
If not, it might be a problem with the SongWriter plugin and we can work from there.
 
Before I didn't even get that pic in my sig. So I looked at my FTP server and saw that the file songout.txt was not being created. So I created it myself, just a blank txt file. I've downloaded it, and it's still blank.
 
It looks like the text file isn't being created by SongWriter then. Have you made sure the SongWriter box is checked in your WMP Plugin settings? You can make sure it's running in the background by clicking Tools>Plugins and checking if "Songwriter Plugin" is visible and checked. If not, the plugin may not have been installed correctly. I just updated the second post with an attachment containing an installer file. Just download and run that.
Also, have you entered the full path of the FTP server you want to publish the file to, along with the correct username and password.

Make sure all of that is okay, and let me know if there's still a problem.
 
Another Update

* Changed the attachment in the 2nd post to a ZIP file containing the Songwriter installer rather than just the plugin files. This will prevent any possible issues caused by incorrect installation.
 
I'm pretty sure I have everything setup correctly. When I go to Tools>Plugins, Songwriter Plugin is visible and checked. I've entered teh corrent username and pass, and correct FTP settings. Same problem though.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back