To Play mp3 files from a remote location in smart phone, we are required to WMPLib.dll’s WindowsMediaPlayerClass Class.
I was not able to find a way to stream the music, then I decided to first save the file on device and then playing file.
<pr
e>
private int currentIndex = 0;
private WMPLib.IWMPPlayer musicPlayer;
XmlDocument xmlDoc = new XmlDocument();
private void Form1_Load(object sender, EventArgs e)
{
Application.DoEvents();
xmlDoc.Load(@”http://doamin.com/songs.xml”);
musicPlayer = new WMPLib.WindowsMediaPlayerClass();
musicPlayer.settings.volume = 100;
musicPlayer.settings.autoStart = true;
play();
}
private void play()
{
//xml document contains the list of songs,
//getting the list of cuurent song
string url = xmlDoc.GetElementsByTagName(“url”)[currentIndex].InnerText;
label1.Text = xmlDoc.GetElementsByTagName(“title”)[currentIndex].InnerText;
System.Net.HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
System.IO.FileStream FileStreamer;
byte[] bBuffer = new byte[1024];
int iBytesRead = 0;
//saving the file, with name mp.mp3
string fName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + “\\mp.mp3″;
FileStreamer = new FileStream(fName, System.IO.FileMode.Create);
System.Net.HttpWebResponse URLRes = (HttpWebResponse)webReq.GetResponse();
Stream sChunks = URLRes.GetResponseStream();
do
{
iBytesRead = sChunks.Read(bBuffer, 0, 1024);
FileStreamer.Write(bBuffer, 0, iBytesRead);
}
while (iBytesRead != 0);
musicPlayer.URL = fName;
musicPlayer.controls.play();
}