ASP Programming Example: Building music Server with ASP

Source: Internet
Author: User
Tags ftp protocol web database

----Music Server is a server that provides music online services, including high-end Web sites that provide 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 has brought a high rate of access.
----Like other sites, music servers include two sections of websites and hardware. Hardware performance and server efficiency are proportional, so how to build a website is the key to a music server. From now on, there are basically two types of websites: one is running in unix/linux environment, using PERL/C/Php/java as CGI programming language, one is running on the win NT Server platform, using asp/wincgi as the background language. The former has high efficiency, but the structure is complex, it is more suitable for large-scale site, the latter is relatively low in programming, and the ODBC driver interface makes the database connection convenient, especially suitable for music server.
----This article will take the ASP 5.0 as the programming environment, Mircosoft Access 97 as the Web database, the Win NT Server 4.0 as the running platform, illustrates the construction steps of the music server.
----A basic music server including music online appreciation, music leaderboards, music theme search and music download four parts. The following will be the main technical aspects of how to achieve the above features.
Planning of Music Theme database
----Music Theme database is the warehouse where the Web site stores the required music data, and its planning greatly affects the structure and efficiency of the entire website. A single form can be built in the database, and multiple forms can be built as primary keys and foreign keys. In this example, for the convenience of the description, the following single-table framework 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 a 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 fired to invoke the corresponding player to execute the file, thus realizing the music online appreciation function. Currently support for. m3u file players are Winamp, Realplayer G2, MusicMatch and so on. When these player software is installed correctly on the client, it is possible to play the. m3u file automatically. So the key to solving the problem is how to generate. m3u files in the background and downstream to the client. The following is a solution based on the FileSystem component built into ASP, and the corresponding program is given.
<%
Dim Choose,path,mydb,myset,sql,fs,mp3
' ##### get the selected song item in the List.htm form
The corresponding ID number and assigned 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) + ")"
' ##### judge the Choose variable, if it does not contain any ID number,
Note No songs are selected in list.htm to terminate the program #####
If choose= "()" Then
Response.Redirect ("list.htm")
Response.End
End If
' ##### set the file path, you need to set the Temp directory's permissions to
Read and Write permissions for anonymous Internet users #####
Path= "E:\inetpub\wwwroot\temp\"
' ##### Create a file object #####
Set fs = CreateObject ("Scripting.FileSystemObject")
Set MP3 = fs. CreateTextFile (path+ "listen.m3u", True)
' ##### Create database object #####
Set Mydb=server.createobject ("Adodb.connection")
Mydb.open "Music"
' ##### retrieves the database and gets the song information #####
Sql= "Select Mp3name,url from" &dbname&
"Where ID in" &choose
Set Myset=tdb.execute (SQL)
Do and not myset.eof
' ##### generate an on-demand song file list #####
MP3. Write ("http +/" +myset ("url") +CHR (10))
Myset.movenext
Loop
' ##### updates the number of on-demand times in the database and
Total number of On demand #####
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: Use this method to control the contents of the. m3u file HTTP header. IIS can be used in Winnt to set the mine content of the. m3u file type. Here's how: Start iis-> Select the Web site where the music server is located-> Click the "Properties" button-> Click on the "HTTP title" tab in the Properties tab that appears-> click the "File Type" button-> Click on the "New type" button-> ". m3u" in "corresponding extension", in the " Content type, fill in the Audio/mpegurl-> and then make sure.
----Music Leaderboard is an indispensable content of music server, its importance is no less than the pageview of a site. It can provide instant information to the fans, guide the appreciation, and dynamically reflect the trend. In the numerous music servers, the leaderboard is also a place where the innovation, with a high click-through rate. In general, the leaderboard includes the total number of On demand, the number of days on demand, total downloads and so on. The specific implementation method is relatively simple. The following SQL statement can be used in a single table: SELECT * from Music order by Total_click. For multiple tables, you can take advantage of a union query SQL statement with a join clause. If you want to limit the number of query records, you can use the count () aggregate function. In this example, if you want to query the first 20 songs on the day, you can use the following statement: SELECT Top * from music ORDER BY Total_click Desc. The function of the leaderboard depends mainly on the planning of the theme database, you can add and delete fields as needed to achieve the corresponding functions (such as increasing the time, singer data, ranking changes, etc.), the SQL statements involved will not be too complex. In short, the leaderboard is the embodiment of a music site features, can be free to play.
Music Theme Search
----mentioned search, many people immediately associate with 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. The efficiency of the search depends on the performance of the database and the efficiency of the SQL statement. At the front desk, you can provide a range of search items and conditional options. In the background, the corresponding query statements are generated in the database according to the form submitted by the foreground, and the query results are returned. For example, the form submitted at the front desk is: Retrieve item = "Shanghai Man Hospital", content = "Jacky", Match condition = "Whole word match", then the SQL statement generated by background is: SELECT * from music where singer= ' Jacky ' ORDER by Edition,id ASC so that all of Jacky's song information can be retrieved and returned by the album category. Also such as the front desk to query the singer name is "Qi Qin", and song name with "Rain" word of all songs (that is, require fuzzy matching), the background generated SQL statement is: SELECT * from music where singer = ' Qi Qin ' and mp3name like '% rain% ' or Der by ID ASC, will return "Winter Rain", "Sun Rain", "ruthless rain ruthless you" and so on. With the right skills and flexible SQL statements, you can get your topic search to work.
Music download function
----Provide music download function, is also a basic function of music server, especially for remote users, will enjoy the songs downloaded to appreciate. Generally there are two ways to provide download, one is directly through HTTP and browser download, the other is to open the music library as an FTP directory, through the FTP protocol download. In this example, the previous method is used, and the number of downloads is tracked in the database. Some sites also according to the needs of the song compression encryption, the password is provided to the formal use of canвt color and anxiety limp fan ≈ feed 1 harmonic sash?
<%
' ##### get the song sign number 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 number of downloads for 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
' ##### Shanghai treatment Impotence Hospital #####
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 forums, chat rooms, polling stations, entertainment news network and so on, can be implemented with ASP one by one. This article is limited in length and is no longer discussed in detail. As long as the front page features a unique style design and complete JavaScript program control, background programming with flexible SQL statements and powerful ASP components, coupled with a thoughtful web database and rich creativity, can build a perfect music server. Interested friends may wish to try, you will create a miracle!

ASP Programming Example: Building music Server with ASP

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.