Elliot Haughin

I'm a freelance web developer.
I build clever, engaging, ass-kicking,
web applications. You want me?

LastfmSharing your music taste could never be easier with CodeIgniter and Lastfm

Just register for lastfm, and install the program on your PC/Mac… then play your tunes in your favourite music player. The ‘recently played’ list will start populating with your track list.

You can use this library to get a list of your recently played songs (like on the right hand side of this blog >>), for your CodeIgniter application.

Using the application is really simple.
Here’s the code for your controller:

$this->load->library('lastfm');
 
$config = 	array(
'user'	 => 'elliothaughin',
'num'	=> 10,
'rss_cache_path'	=> APPPATH.'cache/lastfm-rss-cache',
'cache_time'	=> 300 // 5 minutes
);
 
$this->lastfm->init($config);
 
$data['lastfm'] = $this->lastfm->get_latest();

Then you just need to display them in your view files!

<?php foreach ($lastfm as $song):?>
<li><?=$song['title']?><br />
<?=$song['when']?></li>
<?php endforeach; ?>

Easy peasy huh?

Download Lastfm CodeIgniter Library

REQUIRES: Simplepie CodeIgniter Library

Version: 1.0

Sponsored Links

Comments

  1. clux says:

    hey, just goofing around with this, thanks a lot! But just one thing: your username is hardcoded into the rss_url on line 48.

    i assume it should be something like
    $this->rss_url = http://ws.audioscrobbler.com/1.0/user/‘.$user.’/recenttracks.rss’; ?

  2. clux says:

    i mean
    .$this->user.
    sorry.

  3. Gport says:

    Yep, true.

    change line 48 to:

    $this->rss_url = ‘http://ws.audioscrobbler.com/1.0/user/’.$this->user.’/recenttracks.rss’;

    Thanks for the Lib!!!

  4. Aline says:

    Thank you very much! It works \o/

    I just had to change the line 122 to set my own path location:

    $this->obj->simplepie->cache_location = ‘./assets/includes/’;

Leave a Comment

© Copyright 2010 Elliot Haughin