Guide: WMP9 Now Playing

Discussion in 'Windows Desktop Systems' started by NetRyder, Sep 16, 2003.

  1. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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.

    [​IMG]

    (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>
    
     
  2. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Here is the SongWriter plugin for WMP9:
    (Updated Sept 18 - Now contains an installer file)
     
  3. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    This could be used with the Winamp now playing script to generate the picture i have in my sig.
     
  4. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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 ]
    
     
  5. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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.
     
  6. funky dredd

    funky dredd Moderator

    Messages:
    2,346
    Location:
    Florida
    Thanks NetRyder! I have been waiting to find something like this. :)
     
  7. Bman

    Bman OSNN Veteran Original

    Messages:
    8,799
    Location:
    Ottawa, Ontario
    Nice one NetRyder, thanks alot!!
     
  8. Henyman

    Henyman Secret Goat Fetish Political User

    great :cool: downloaded ;)
     
  9. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    cool, I'll definetly try this one. :)
     
  10. Tabula Rasa

    Tabula Rasa Stranger Than Kindness Political User

    Messages:
    3,233
    Location:
    Israel
    Woah! thanks Netryder!
     
  11. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Glad it was useful :)
    @X-Istence: Thanks for the .htaccess PNG-addon. That looks interesting ;)
     
  12. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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)
     
  13. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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 :).
     
  14. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    I'm having problems. I'm playing a song right now, but I don't get it displayed in my sig.
     
  15. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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.
     
  16. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    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. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    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.
     
  19. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    sweet, i'll have to try this out when i get some time. thanks.
     
  20. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    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.