asp.net Web services and flash create MP3 players

Source: Internet
Author: User
Tags web services root directory

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.