nowPlaying is a PHP class for displaying currently playing tracks on Last.FM.
Using the class is simple. Assuming the class file is in the same directory as the file you are attempting to include it in, just use the following line to include the class;
include_once("class.listeningNow.php");Next, set up the class and fetch the track.
$np = new nowPlaying("lastFMUsername","lastFMAPIKey"); // Create the object and instantiate the class
$np->nowPlaying(); // Fetch and display the currently playing track.You can find your Last.FM API key at http://www.last.fm/api/accounts
nowPlaying allows you to format what is displayed about the track, and in the order. To change the formatting in the above example, you could use;
$np->set_format("[ARTIST] - [TRACK]");Which would print something like;
Artist Name - Track Name
The formatting can handle additional characters, as shown with the "-". The options available currently are
[ARTIST]
[TRACK]
There are plans to include conditional formatting for stand-out tracks such as those which are "loved" or liked.
You can set an alternative message to be displayed when there is no response or nothing being listened to. You can do this as follows.
$np->set_message("I'm not listening at the moment...");You can set a variable with the response of nowPlaying() by passing a "false" parameter to it. For instance;
$foo = $np->nowPlaying(false);