<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d13376580\x26blogName\x3dThe+GeekWithin\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://geekwithin.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://geekwithin.blogspot.com/\x26vt\x3d-8111287070889316650', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

The GeekWithin

Friday, January 20, 2006

New Now Playing Sidebar

Messing around I found a really cool Windows Media Player plug-in (unfortunately now longer supported, but source is available) that can save an XML file with data about the current song you are listening to.

There are many options, but only four that I liked: album cover art (small size), album name, song name, and artist name. The coolest feature of all was that you could have it FTP the XML file and a jpg of the art to any server you have access to. WOW!

So, I took that and worked it so that the files were uploaded to a service I have that also allows ASP.Net execution. I added some quick code to the code behind page (C#) starting with four public variables:
public string album;
public string artist;
public string song;
public string image;

And added this to the page_load event:
string filepath = Server.MapPath("songout.xml");
System.Data.DataSet ds = new System.Data.DataSet("nowplaying");
ds.ReadXml(filepath,System.Data.XmlReadMode.InferSchema);
artist = ds.Tables[0].Rows[0]["artist"].ToString();

if (artist == "Stopped")
{
image = "nosong.jpg";
artist = "";
song = "";
album = "Not Listening";
}
else
{
image = "smsongout.jpg";
album = ds.Tables[0].Rows[0]["album"].ToString();
song = ds.Tables[0].Rows[0]["title"].ToString();
}

Adding it to Blogger was as easy as using the IFRAME HTML tag. I plan to change it to an object tag later seeing as the IFRAME tag is on its way out, but for now it will do the job.

Final product? Check it out on the sidebar... way cool!


 

Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.