Yesterday installed Flash MX Pro, looked at the next introduction, indeed added a lot of new features, added a lot of data components, and then feel asp.net development of Web services so simple, so whim: I do not use C # and Flash to do a player ah. Here are some simple principles.
Write a Web service in C # that lists the. mp3 files for a given directory (mainly with some members of the System.IO) and adds it to a ArrayList, and finally publishes the ArrayList as a Web service. Then use Flash MX 2004 to create a flash document, use the Webserviceconnector component to get the Web service just published, and then bind the returned results to Flash's list component, and finally, add an action to the list component to double-click Wait for the mp3 file that you double-click to play.
First, the development of Web services
The specific code is as follows, very simple, no longer said, Web services development We are very familiar with, don't say such a simple example. Here is a new mp3 folder in the root directory of the site, and then put some MP3 files inside, and finally preview the test of this Web service, the preview of the address specific to the virtual directory you established the path, I have the following.
Http://onlytiancai/bak/flashmp3/mp3services.asmx
<%@ Webservice Language="C#" class="mp3Service" %>
using System;
using System.Collections;
using System.Web.Services;
using System.IO;
public class mp3Service : System.Web.Services.WebService
{
public mp3Service()
{
}
[WebMethod]
public ArrayList GetMp3()
{
ArrayList mp3List =new ArrayList();
string mp3path = Server.MapPath("mp3");
try
{
DirectoryInfo di = new DirectoryInfo(mp3path);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
if(fiTemp.Extension.ToLower() == ".mp3"||fiTemp.Extension.ToLower() == ".wma")
{
mp3List.Add(fiTemp.Name);
}
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
return mp3List;
}
}