Building a music server with ASP

Source: Internet
Author: User
Tags count ftp iis client create database ftp protocol web database
Server


The----music server is a server that provides online music services, including high-end portal services, web databases, and low-end operating platforms and hardware facilities. At present, there are many such sites on the Internet and intranet, especially in some high-speed broadband LAN (such as Campus network), music server to the Internet friends to provide a good place for leisure and entertainment, but also to the site brought a high rate of access.

----Like other sites, the music server includes two parts of the Web site and hardware. Hardware performance and server efficiency are proportional, so how to build a Web site is the key to a music server. From the current point of view, the site has two basic types: one is running in the Unix/linux environment, using PERL/C/Php/java, such as CGI programming language, one is running on the win NT Server platform, using asp/wincgi as the background language. The former is efficient, but complex structure, more suitable for large sites, the latter is relatively low programming difficulty, and the use of ODBC-driven interface, database connection is convenient, especially suitable for the music server.

----This article will use ASP 5.0 as the programming environment, Mircosoft Access 97 as the Web database, Win NT Server 4.0 as the platform, and illustrate the steps of building the music server.

----A basic music server includes four parts including music online appreciation, music charts, music theme search and music downloads. The following will mainly discuss how to implement the above functionality from a technical standpoint.

Planning of Music Theme database
----Music Theme database is the warehouse where the Web site stores the music information needed, and its planning affects the structure and efficiency of the whole website to a great extent. A single form can be built in a database, or multiple forms can be built in the form of primary and foreign keys. For the convenience of the illustration in this example, the following single table frame is built: (Music.mdb)


Music Online Appreciation
----online appreciation means that the client uses the player to play the server-side music files. The principle is that when the client submits the music menu to the server, the server generates the corresponding. m3u file and downlink the file through the HTTP protocol to the client, and the client is excited to invoke the appropriate player to execute the file, thus realizing the music online appreciation function. The players currently supporting. m3u files are Winamp, RealPlayer G2, MusicMatch, and so on. When these player software is properly installed on the client, the. m3u file can be played automatically. So the key to solving the problem is how to generate the. m3u file in the background and downlink to the client. The following uses the filesystem component built into the ASP to give a solution and give the appropriate program.
<%
Dim Choose,path,mydb,myset,sql,fs,mp3
' ##### gets the song item selected in the List.htm form
The corresponding ID number and assign to the string variable choose #####
Choose= "("
For I=3 to Request.form.count
Choose=choose+request.form (i) + ","
Next
Choose=left (Choose,len (choose)-1) + ")"
' ##### to judge the Choose variable, if it does not contain any ID number,
Note that no songs are selected in List.htm, terminating the program #####
If choose= "()" Then
Response.Redirect ("list.htm")
Response.End
End If
' ##### set the file path, you need to set the TEMP directory permissions to
Have read & Write permission for anonymous users on the Internet #####
Path= "E:\inetpub\wwwroot\temp\"
' ##### Create a file object #####
Set fs = CreateObject ("Scripting.FileSystemObject")
Set MP3 = fs. CreateTextFile (path+ "listen.m3u", True)
' ##### Create database Objects #####
Set Mydb=server.createobject ("Adodb.connection")
Mydb.open "Music"
' ##### retrieve the database and get the song information #####
Sql= "Select Mp3name,url from" &dbname&
"Where ID in" &choose
Set Myset=tdb.execute (SQL)
Do as not myset.eof
' ##### generate on-demand song file list #####
MP3. Write ("http://" +myset ("url") +CHR (10))
Myset.movenext
Loop
' ##### update the number of days on demand in the database and
Total number of requests #####
Sql= "Update music set click=click+1,
this=this+1 where ID in "&choose
Mydb.execute (SQL)
' ##### Cancel Object #####
Set myset=nothing
Mydb.close
Set mydb=nothing
Mp3.close
Set mp3=nothing
' ##### to download the file to the user #####
Response.Redirect ("listen.m3u")
Response.End
%>

----NOTE: When using this method, you control the contents of the. m3u file HTTP headers. IIS can be used in Winnt to set the mine content of the. m3u file type. The specific operation is as follows: Start iis-> Select the Web site where the music server is located-> Click the "Properties" button-> Click the "HTTP title" card in the Properties tab that appears-> click on the "File type" button-> Click the "New Type" button-> "fill in the appropriate extension". m3u ", in" Content type "Audio/mpegurl"-> and then all the way OK.

Music charts
----Music list is an indispensable part of the music server, its importance is no less than the pageview of a site. It can provide instant information to fans, guide appreciation, and dynamically reflect trends. In a number of music servers, the list is also the new place, with a high rate of hits. Generally speaking, the list includes the total number of on-demand, the day on demand, the total number of downloads and so on. The concrete implementation method is relatively simple. The following SQL statements can be used in a single table: SELECT * from music orders by Total_click. If you have multiple tables, you can use Federated query SQL statements with join clauses. If you want to limit the number of query records, you can use the count () collection function. If, in this case, you want to query the first 20 songs of the day, you can use the following statement: Select the From music order by Total_click Desc. The function of the list mainly depends on the theme database planning, you can add and delete fields as needed to achieve the corresponding functions (such as increasing the time of the list, singer data, ranking changes, etc.), the SQL statements involved will not be too complex. In short, the list is to reflect the characteristics of a music site, you can freely play.
Music topic Search
----mentioned the search, many people immediately associate to Yahoo, Soho and other famous sites, and quite mysterious feeling. In fact, the search engine in the database is not difficult, because the database built-in data engine has provided a good foundation. Search efficiency depends on the performance of the database and the efficiency of the SQL statement. In the foreground, you can provide a range of retrieval items and conditional options. In the background, according to the form submitted by the foreground, generate the corresponding query statement in the database execution, and the query results returned. For example, the form presented at the front desk is: Retrieve item = "singer Name", content = "Jacky", Match condition = "Match Whole word", then the SQL statement generated in the background is: SELECT * from music where singer= ' Jacky ' ORDER by Edition,id ASC so that you can retrieve all of Jacky's song information and return it by album category. Also as the foreground to query the singer name "Chin", and the song name with "Rain" word of all songs (that is, the requirement for fuzzy matching), then the background generated SQL statements: SELECT * from music where singer = ' chin ' and mp3name like '% rain% ' or Der by ID ASC, will return "Winter Rain", "Sun Rain", "relentless rain ruthless you" and so on. Just use the appropriate techniques and flexible SQL statements to make your subject search work as vividly as possible.
Music download function
The----provides music downloading function, is also a music server's basic function, especially to the remote user, will love the song to be able to appreciate after downloading. Generally there are two ways to provide downloads, one is directly through HTTP and browser download, the other is to open the music library as an FTP directory, through the FTP protocol to download. This example takes the previous approach and tracks the number of downloads in the database. Some sites also compress and encrypt songs as needed, which is also a good way to make them available to the full user. In this case the procedure is as follows:
<%
' ##### get the song logo ID #####
Id=request ("id")
Set Tdb=server.createobject ("Adodb.connection")
Tdb.open "Music"
Sql= "Select Mp3url from music where id =" &id
Set Tset=tdb.execute (SQL)
If Tset.eof Then
Response.End
Else
' ##### update the download number of songs in the database #####
Sql= "Update music set Total_down=total_down
+1 WHERE id = "&id
Tdb.execute (SQL)
Downfile=tset ("url")
Tdb.close
Set tset=nothing
Set tdb=nothing
End If
If downfile= "" or IsNull (downfile) then Response.End
downfile= "http://" +downfile
' ##### download the corresponding song #####
Response.Redirect (Downfile)
Response.End
%>

----The above steps to build a basic music server. Of course, a complete music server can also include singer information, fan forum, chat room, polling station, entertainment news network and so on functions, can be implemented with ASP one by one. This article is limited to space and is no longer discussed in detail. As long as the front page uses a unique style design and perfect JavaScript program control, background programming using flexible SQL statements and powerful ASP components, coupled with a well-designed web database and rich ideas, you can build a perfect music server. Interested friends may wish to try, you will create a miracle!


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.