• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Guide: WMP9 Now Playing

#1
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.


(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>
 
#4
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 ]
 

X-Istence

*
Political User
#5
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.
 
#12
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)
 

X-Istence

*
Political User
#13
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 :).
 
#15
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.
 

Grandmaster

Electronica Addict
Political User
#16
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.
 
#17
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.
 
#18
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.
 

Grandmaster

Electronica Addict
Political User
#20
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies