The method of building music server with ASP

Source: Internet
Author: User
Tags create database

Music server is a server that provides online music services, including high-end portal services, web databases, and low-end operating platforms, 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.

----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.

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.