![]() |
Web Development »
ASP.NET »
General
Advanced
License: The Code Project Open License (CPOL)
Create A Music Playlist for Windows Media Player At Your WebpageBy Mohd Arshad (Sam)This article will help you to create a music playlist at your webpage and change the running song accordingly on embedded media player. + Embedding a Windows Media Player using JavaScript. |
C# (C#2.0), Javascript, HTML, Windows (Win2K, WinXP, Win2003, Vista), .NET (.NET2.0), ASP.NET, Visual-Studio (VS2005), ADO.NET, WebForms, Architect, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article will help you to create a music playlist at your webpage and change the running song accordingly on embedded media player. + Embedding a Windows Media Player using JavaScript. You'll embed windows media player with a new filepath fetched from database (using cookies), each time when a new song title has been clicked at playlist.
Create a table in master database (or any other database, relevent to connection string you are using) like this…
create table medPL(sid int identity(1,1), sname varchar(20), surl varchar(100))
Now insert song titles and urls like this…
insert into medPL (sname,surl) values ('Mr. Lonely','c:\lonely.mpg')
Make sure that you provided correct path and file name and type.
Download .ZIP file, extract two pages (Default.aspx, Default.aspx.cs). Create a new website in VS using Visual C# at codebehind. Delete the existing Default.aspx page from your site. Now, right click the project and add existing item – which are your downloaded pages. Run and enjoy...
Creating your playlist, using Grid HyperLinkField
<div>
<asp:GridView ID="grdMPL" AutoGenerateColumns="false" DataSourceID="dsMedPL" runat="server">
<Columns>
<asp:HyperLinkField
HeaderText="Playlist"
DataTextField="sname"
DataNavigateUrlFields="sid"
DataNavigateUrlFormatString="Default.aspx?sid={0}"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsMedPL" ConnectionString="server=.;database=master;uid=sa;pwd=sa"
SelectCommand="select sid,sname from medPL"
runat="server">
</asp:SqlDataSource>
</div>
<div id="divPlayer"></div>
<asp:SqlDataSource
id="dsSelURL"
ConnectionString="server=.;database=master;uid=sa;pwd=sa"
SelectCommand="select surl from medPL where sid=@sid"
Runat="server">
<SelectParameters>
<asp:QueryStringParameter Name="sid" QueryStringField="sid" />
</SelectParameters>
</asp:SqlDataSource>
<script type="text/javascript">
function getCookieValue()
{
var cookieValue = document.cookie;
var cookieStartsAt = cookieValue.indexOf(" " + "songURL" + "=");
if (cookieStartsAt == -1)
{
cookieStartsAt = cookieValue.indexOf("songURL" + "=");
}
if (cookieStartsAt == -1)
{
cookieValue = null;
}
else
{
cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
if (cookieEndsAt == -1)
{
cookieEndsAt = cookieValue.length;
}
cookieValue = unescape(cookieValue.substring(cookieStartsAt,
cookieEndsAt));
}
return cookieValue;
}
document.getElementById('divPlayer').innerHTML='<object id="mediaPlayer" height="300" width="300" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" visible="true">+ getCookieValue() + '"/></object>';
</script>
protected void Page_Load(object sender, EventArgs e)
{
//Accessing the selected song URL
GridView grd = new GridView();
grd.DataSource = dsSelURL;
grd.DataBind();
//Creating a Cookie by giving this the value of Selected Song URL.
if (grd.Rows.Count == 1)
{
Response.Cookies["songURL"].Value = grd.Rows[0].Cells[0].Text;
}
}
Now your Music Playlist Project is complete. Run and Enjoy...
I hope you will find this article helpful in programming for Music Playlist, Embedding Windows Media Player using Javascript, Using QueryString, Using Cookies. For more information you can contact me at arshad@m-arshad.co.cc Good Luck!
| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 22 Nov 2008 Editor: |
Copyright 2008 by Mohd Arshad (Sam) Everything else Copyright © CodeProject, 1999-2010 Web18 | Advertise on the Code Project |