You really should generate a static M3U for scalability, precalculation
and caching reasons.
Checkout my media streaming portal demo at
http://www.wanfear.com/~mbrito/Content/HTML/MediaStreaming.html
This routine was originally written to create M3U's from MP3's with
Database tracking of Content, but I extended it to support any content
type such as Video, Pictures, Music, Products for Sale, Streaming
Music, Software, etc.
Heres a paste:
protected void UploadStreamingContent_Click(object sender,
System.EventArgs e)
{
this.adptrMusic.InsertCommand.Parameters["artist"].Value=this.txtName.Text;
this.adptrMusic.InsertCommand.Parameters["email"].Value=this.txtEmail.Text;
this.adptrMusic.InsertCommand.Parameters["message"].Value=this.txtMessage.Text;
this.adptrMusic.InsertCommand.Parameters["title"].Value=this.txtTitle.Text;
this.adptrMusic.InsertCommand.Parameters["featured"].Value=this.chkMusicFeatured.Checked;
string contentfilename=this.fileSong.Value;
string picturefilename = this.filePicture.Value;
if (contentfilename == null ||
contentfilename.Trim().Length == 0)
contentfilename = picturefilename;
// filename
if (contentfilename.LastIndexOf("\\") > 0)
{
contentfilename =
contentfilename.Substring(contentfilename.LastIndexOf("\\") + 1);
}
Regex regex = new Regex("[^A-Za-z1-9\\.]");
contentfilename = regex.Replace(contentfilename, "-");
if (picturefilename.LastIndexOf("\\") > 0)
{
picturefilename =
picturefilename.Substring(picturefilename.LastIndexOf("\\") + 1);
}
if (contentfilename.ToUpper().EndsWith("MP3"))
{
string m3ufilename = contentfilename.Substring(0,
contentfilename.LastIndexOf(".") + 1) + "m3u";
string m3ufqfn =
this.Request.MapPath(this.Request.ApplicationPath) + "\\Music\\" +
m3ufilename;
string mp3url =
ConfigurationSettings.AppSettings["MusicURLPrefix"].ToString() +
contentfilename;
if (File.Exists(m3ufqfn))
{
File.Delete(m3ufqfn);
}
FileStream fs = File.Create(m3ufqfn, 1024);
Byte[] info = new UTF8Encoding(true).GetBytes(mp3url);
fs.Write(info, 0, info.Length);
fs.Close();
contentfilename= m3ufilename;
}
string
pf=this.Request.MapPath(this.Request.ApplicationPath)+
"\\Pictures\\"+picturefilename;
if(File.Exists(pf))
File.Delete(pf);
this.filePicture.PostedFile.SaveAs(this.Request.MapPath(this.Request.ApplicationPath)+
"\\Pictures\\"+picturefilename);
pf=this.Request.MapPath(this.Request.ApplicationPath)+
"\\Music\\"+contentfilename;
if(File.Exists(pf))
File.Delete(pf);
this.fileSong.PostedFile.SaveAs(this.Request.MapPath(this.Request.ApplicationPath)+
"\\Music\\"+contentfilename);
this.adptrMusic.InsertCommand.Parameters["contentfilename"].Value=contentfilename;
this.adptrMusic.InsertCommand.Parameters["picturefilename"].Value=picturefilename;
this.adptrMusic.InsertCommand.Connection.Open();
this.adptrMusic.InsertCommand.ExecuteNonQuery();
this.adptrMusic.Fill(this.dsMusic.Tables["Content"]);
this.dgSongs.DataBind();
this.txtName.Text=string.Empty;
//this.txtEmail.Text=string.Empty;
this.txtMessage.Text=string.Empty;
this.txtTitle.Text=string.Empty;
this.lblSongAdded.Visible=true;
this.chkMusicFeatured.Checked=false;
}
Regards,
Mark B.