Class that returns information about the current track playing, using the Last.fm API.
Requires PHP 5, and a Last.fm API key: http://www.last.fm/api/account
Author: Erik Jansson - hello@erikjansson.net
require_once 'nowplaying.class.php';
$nowPlaying = new NowPlaying('Username', 'API key');
$nowPlaying->setNoTrackPlayingMessage('My custom message!'); // optional
echo $nowPlaying->getNowPlaying();
-
Assuming the class file resides in the same directory as your script, include it as such:
require_once 'nowplaying.class.php';
-
Then, instantiate the class:
$nowPlaying = new NowPlaying('Username', 'API key');
- The first parameter is the Last.fm username you want data from.
- The second parameter is the API key which you will find in your API account after signing up: http://www.last.fm/api/account
-
To display the current track playing, call the getNowPlaying() method:
echo $playing->getNowPlaying();
-
When no music is currently being played, a message will be shown saying so. This message can be customized with
setNoTrackPlayingMessage()
: `$playing->setNoTrackPlayingMessage('My custom message!');Remember to call this method before
getNowPlaying()
, otherwise your custom message won't be used.
Do whatever you want with this. Kthxbai!