by nolovelust
30. March 2010 21:15
UPDATE 14/01/2011 Shoutcast stopped providing public API for their dataabse. You need to register at http://dev.aol.com/SHOUTcast/ to get your API Key.
After that you can simply edit /App_Code/ScESettings.cs and replece settings with below ones.
public static string strURLsearch = "http://api.shoutcast.com/legacy/stationsearch?k=YOURAPIKEY&search=";
public static string strURLbrowse = "http://api.shoutcast.com/legacy/genresearch?k=YOURAPIKEY&genre=";
Before all here is the complete script shoutcast-mobile.zip (592.97 kb) and here is the working version at http://mobile.web.tr/shoutcast
This app designed for high-end mobile phones that are capable of doing AJAX requests
Now, lets start from Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shoutcast Mobile Internet radio database</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
<meta name="keywords" content="shoutcast, online radio, mobile radio, shoutcast mobile" />
<meta name="description" content="Shoutcast for mobile devices and iphone. Listen 100s of internet radios on your mobile phone" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="RadioUpdater" runat="server" ScriptMode="Release">
</asp:ScriptManager>
<asp:UpdateProgress ID="ajaxupdateindicator" DynamicLayout="true" runat="server"><ProgressTemplate><div style="background-color:#CF4342;color:#fff;top:0px;right:0px;position:fixed;">Loading...</div></ProgressTemplate></asp:UpdateProgress>
<div>
<div class="top">
<table id="table1" style="width: 100%;">
<tr>
<td style="text-align: left;">
<img src="logo.png" alt="Shoutcast mobile" title="Shoutcast mobile"/>
</td>
<td style="text-align: right;">
<asp:DropDownList ID="GenreList" runat="server">
</asp:DropDownList> <asp:DropDownList ID="BitRates" runat="server">
<asp:ListItem Text="All bitrates" Value="0"></asp:ListItem>
<asp:ListItem Text="256 kbps" Value="256"></asp:ListItem>
<asp:ListItem Text="192 kbps" Value="192"></asp:ListItem>
<asp:ListItem Text="128 kbps" Value="128"></asp:ListItem>
<asp:ListItem Text="96 kbps" Value="96"></asp:ListItem>
<asp:ListItem Text="64 kbps" Value="64"></asp:ListItem>
<asp:ListItem Text="48 kbps" Value="48"></asp:ListItem>
<asp:ListItem Text="32 kbps" Value="32"></asp:ListItem>
<asp:ListItem Text="24 kbps" Value="24"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="ViewB" runat="server" Text="Go"
onclick="ViewB_Click" />
</td>
</tr>
</table>
</div>
<div class="gap"></div>
<asp:UpdatePanel ID="RadioUpdaterUpdatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ViewB" EventName="Click" />
</Triggers>
<ContentTemplate>
<div class="list" id="list">
<asp:ListView ID="StationList" runat="server" ItemPlaceholderID="itemContainer">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemContainer" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<a target="_blank" href="http://yp.shoutcast.com/sbin/tunein-station.pls?id=<%#Eval("id") %>"><%#Server.HtmlEncode(Eval("name").ToString())%>
<span class="tiny"><%#Server.HtmlEncode(Eval("br").ToString())%> kbps</span>
</a>
</li>
</ItemTemplate>
<EmptyDataTemplate>
<li>No station found</li>
</EmptyDataTemplate>
<EmptyItemTemplate>
<li>No station found</li>
</EmptyItemTemplate>
</asp:ListView>
<div class="gap"></div>
<div class="center">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="StationList" PageSize="5">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
FirstPageText="<<"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:NumericPagerField
PreviousPageText="<"
NextPageText=">" ButtonType="Button"
ButtonCount="5" />
<asp:NextPreviousPagerField
ButtonType="Button"
LastPageText=">>"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:TemplatePagerField>
<PagerTemplate>
<br />
<b>Page
<asp:Label runat="server" ID="CurrentPageLabel"
Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
of
<asp:Label runat="server" ID="TotalPagesLabel"
Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
(<asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
records)
</b>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
<div class="gap"></div>
<form action="search.aspx">
<div class="center">
<input id="SearchT" type="text" name="q"/><input id="Submit1" type="submit" value="Search" />
<br />
<a href="shoutcast.zip">Get source code source code</a>
<br />
<span class="small">We have no affiliation to <a href="http://shoutcast.com/">http://shoutcast.com/</a>. We simply provide mobile interface to their public web site.</span>
</div>
</form>
</body>
</html>
Codebehind Default.aspx.cs
using System;
using System.Data;
using System.Linq;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
ClientTarget = "ie5";
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
BindListView();
DataPager1.PageSize = 5;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGenres();
}
}
private void BindGenres()
{
ScGenres g = new ScGenres();
GenreList.DataSource = g.GetGenres();
GenreList.DataTextField = "cat_Text";
GenreList.DataValueField = "cat_Text";
GenreList.DataBind();
}
protected void ViewB_Click(object sender, EventArgs e)
{
BindListView();
}
protected void BindListView()
{
int filterBitRate = ScEngine.ReturnNumeric(BitRates.SelectedValue.ToString());
DataTable dt = new DataTable();
dt = GetListOfStations(GenreList.SelectedValue.ToString()).Tables[1];
object LINQfilteteredResult;
if (filterBitRate == 0)
{
LINQfilteteredResult = (from dr in dt.AsEnumerable()
orderby ScEngine.ReturnNumeric(dr.Field("lc")) descending
select new
{
id = dr.Field("id"),
name = dr.Field("name"),
br = dr.Field("br"),
ct = dr.Field("ct"),
lc = dr.Field("lc")
}).ToList();
}
else
{
LINQfilteteredResult = (from dr in dt.AsEnumerable()
where (ScEngine.ReturnNumeric(dr.Field("br")) == filterBitRate)
select new
{
id = dr.Field("id"),
name = dr.Field("name"),
br = dr.Field("br"),
ct = dr.Field("ct"),
lc = dr.Field("lc")
}).ToList();
}
//StationList.DataSource = GetListOfStations(GenreList.SelectedValue.ToString());
StationList.DataSource = LINQfilteteredResult;
StationList.DataBind();
//columns returned are
//name - station name
//mt - media type
//id - station id
//br - bitrate
//genre - genre
//ct - current title
//lc - listener count
}
private DataSet GetListOfStations(string genre)
{
if (Cache["SCGenreList" + genre] == null)
{
ScEngine se = new ScEngine();
DataSet ds = new DataSet();
ds = se.GetStationList(genre, "list");
if (ds != null)
{
//Cache["GenreList" + genre] = ds;
Cache.Insert("SCGenreList" + genre, ds, null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(180));
}
return ds;
}
else
{
return (DataSet)Cache["SCGenreList" + genre];
}
}
}