Feb
21
2010
--

Embed the Last.fm player into your own website

I decided to write this entry in English. Mainly because the requests for this guide were also written in English. :) But since my Windows is German some screenshots will be in German, too.

I noticed that copying the code doesn’t always work right. Especially the quotes “” are often interpreted wrong! When facing problems you should write the code on your own.

  1. You should know what HTML is :) and be able to edit it.
  2. Open the site of the Last.fm song you want to embed. For example: http://www.lastfm.de/music/Illo/_/Marseille
  3. Right-click with the mouse anywhere on the site and search your context menu for something like “show source code”.
    kontextmenu
  4. Search the code for id=”player”.
    idplayer
  5. In this <div id=”player”> you can find <noscript> … CODE … </noscript>.
    noscriptarea
  6. Copy the whole code like seen on the screenshot and paste it in a own <div> … CODE … </div> in your site. In WordPress just write a new article, use the HTML view and paste the whole code:
    pastecode
  7. You can place this div everywhere (inside a HTML document). I already asked the Last.fm team if they’re ok with this solution since copyright may be an issue. As you can read here, they think it’s fine.
  8. But there’s still one problem: The player starts immediately after the page was loaded. Most people, including me, don’t like it if a website makes “noise” without permission. I usually work with script.aculo.us to show/hide an element. But simple javascript get’s the job done, too.
  9. First you have to add an unique id and a style tag to your div:

    <div id=”id-illo-lastfm” style=”display: none;”> … CODE … </div>

  10. Then you need a link where the visitor can start the player:

    <p><a href=”javascript:play()”>Play</a></p>

    And a function, which is called by the link:

    <script type=”text/javascript”>
    function play() {
    document.getElementById(“id-illo-lastfm”).style.display = “block”;
    }
    </script>

  11. In the end your code should look like:
  12. Finally, our example:


Play

Jan
25
2010
4

Projekt: Spezialthemen der Medieninformatik – done

Wie bei Datenbanken werde ich das erstellte Silverlight Tutorial und die zugehörigen Beispiele bald zum Download bereitstellen.

Seite 1 von 11
© 2009-2013 - Volker Daschner Creative Commons Lizenzvertrag