I have an FTP directory that I keep my music in, and I have a Windows Play List file in it (.wpl). Windows Playlist Files are human readable xml files you can alter in notepad, so when I add a new song to the directory, I just open the file and add another line. A wpl file looks like this:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.3646"/>
<title>Playlist1</title>
</head>
<body>
<seq>
<media src="http://blogbybob.com/music/mysong.wma" mce_src="http://blogbybob.com/music/mysong.wma"/>
</seq>
</body>
</smil>
So, I had a thought one day. Just the one, of course. Would it be nice if I could add the file, and have it show up automatically when I opened media player?
Well, amazingly enough, it is actually pretty easy to do. The main thing to do is "trick" IE into thinking that your wonderful aspx page is actually a wpl file. Fire up Visual Studio, start a new Web Site and go into your default.aspx file.
Highlight all that crap and delete it. Wait, I mean, all of it but the first line. My bad. And I actually named my file music.aspx, but whatever.
Anyhow change the file contents to look like this:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="music.aspx.cs" Inherits="_Music" %>
<?
wpl version="1.0"?>
<
smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.3646"/>
<title>musicbybob</title>
</head>
<body>
<seq>
<asp:Literal runat="server" ID="litPlaylist" />
</seq>
</body>
</smil>
except your first line should still point to whatever code behind you are using. Right click that guy and choose View Code.
We are going to get rid of all but 2 of the using statements and add some code to the Page_Load event. When you are done it should look like this:
using
System;
using System.IO;
public
partial class _Music : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "video/x-ms-wma";
Response.AddHeader("Content-Disposition", "inline;filename=musicbybob.wpl");
litPlaylist.Text = string.Empty;
DirectoryInfo d = new DirectoryInfo(Server.MapPath("music"));
foreach (FileInfo f in d.GetFiles())
{
litPlaylist.Text += "<media src=\"http://" + Request.Url.Host +"/"+ Request.ApplicationPath + "/music/" + f.Name + "\"/>";
}
}
}
Except your class name should match whatever is in your aspx page. Yeah, I used some crappy variable names and was all around lazy, but it works, and sometime I *like* to be lazy. This will read anything in the music folder below where this file lives. You can also add other wpl files in the music folder that point to other places if you have music spread around. Music added to those "other" places won't be dynamically added though. The code also doesn't navigate subdirectories in your music folder.
Or so I assume, I never actually tried it.
Anyhow, to see this in action, click the Radio button in the main navigation menu above.
Update:Download the code here
This post is brought to you by the letter 'M'