Music Server refers to a server that provides online music services. It includes high-end websites 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 LANs (such as campus networks). Music servers provide Internet friends with a good place for leisure and entertainment, and at the same time it also brings convenience to the website. Higher access rate.
----Like other sites, the music server includes two parts: website and hardware. Hardware performance and server efficiency are directly proportional, so how to build a website is the key to a music server. From the current point of view, there are basically two types of websites: one is running in a Unix/Linux environment, using Perl/C/Php/Java, etc. as CGI programming language; the other is running on the Win NT Server platform, using ASP /WinCGI is used as the background language. The former has high operating efficiency, but has a complex structure, so it is more suitable for large sites; the latter has relatively low programming difficulty, and uses an ODBC driver interface to facilitate database connection, making it especially suitable for music servers.
----A basic music server includes four parts: online music appreciation, music rankings, music theme retrieval and music download. The following will mainly discuss how to implement the above functions from a technical perspective.
Planning of music theme database
----The music theme database is a warehouse for storing the music materials required by the Web site. Its planning affects the structure and efficiency of the entire website to a great extent. A single form can be created in the database, or multiple forms can be created in the form of primary keys and foreign keys. In this example, for the convenience of explanation, the following single-table framework is built: (music.mdb)
Listen to music online
----Online listening means that the client uses the player to play music files on the server side. The principle is that after the client submits the music menu to the server, the server generates the corresponding .m3u file and downloads the file to the client through the HTTP protocol; the client will be stimulated to call the corresponding player to execute the file, thus achieving Music online listening function. Players that currently support .m3u files include Winamp, RealPlayer G2, Musicmatch, etc. When these player software are correctly installed on the client, they can automatically play .m3u files. So the key to solving the problem lies in how to generate the .m3u file in the background and download it to the client. The following uses the built-in FileSystem component in ASP to give a solution and the corresponding program.
<%
dim choose,path,mydb,myset,SQL,fs,mp3
'##### Get the selected song item in the list.htm form
The corresponding id number is 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,
Description: No songs are selected in list.htm, terminate the program #####
if choose=() then
response.redirect(list.htm)
response.end
end if
'##### To set the file path, you need to set the permissions of the temp directory to
Have read & write permissions for internet anonymous users #####
path=E:/inetpub/wwwroot/temp/
'##### Create 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
'##### Search the database and get song information#####
SQL=select mp3name,url from &dbname&
where id in&choose
set myset=tdb.execute(SQL)
do while not myset.eof
'##### Generate on-demand song file list#####
mp3.Write(http://+myset(url)+chr(10))
myset.movenext
loop
'##### Update the number of on-demand views and the number of views on the day in the database
Total number of views#####
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
'##### Download this file to user #####
response.redirect(listen.m3u)
response.end
%>
----Note: When using this method, you must control the content of the Http header of the .m3u file. In Winnt, IIS can be used to set Mine content of .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 the File Type button —> Click the New Type button —> In the corresponding Fill in .m3u in the extension, fill in audio/mpegurl in the content type —> and then confirm all the way.
music charts
----The music ranking list is an indispensable content of the music server, and its importance is no less than the Pageview of a site. It can provide fans with real-time information, guide appreciation, and dynamically reflect trends.
Among many music servers, the ranking list is also a place to introduce new ones, with a high click-through rate. Generally speaking, the ranking list includes the total number of times on demand, the number of times on demand that day, the total number of downloads, etc. 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. If there are multiple tables, you can use a joint query SQL statement with a join clause. If you want to limit the number of query records, you can use the count() collection function. In this example, if you want to query the top 20 most requested songs on the day, you can use the following statement: select top 20 * from music order by total_click desc. The function of the ranking mainly depends on the planning of the theme database. You can add or delete fields as needed to achieve corresponding functions (such as adding time to enter the list, singer information, ranking changes, etc.), and the SQL statements involved will not be too complicated. . In short, the rankings reflect the characteristics of a music website and can be used freely.
Music theme search
----When it comes to search, many people immediately think of famous sites such as Yahoo and Soho, and they feel quite mysterious. In fact, it is not difficult to install a search engine in a database, because the built-in data engine in the database already provides a good foundation. The search efficiency depends on the performance of the database and the efficiency of the SQL statement. In the front desk, a series of search items and condition options can be provided. In the background, based on the form submitted by the front desk, the corresponding query statement is generated and executed in the database, and the query results are returned. For example, the form submitted at the front desk is: search item = singer name, content = Jacky Cheung, matching condition = whole word match, then the SQL statement generated in the backend is: select * from music where singer = 'Jacky Cheung' order by edition, id asc, In this way, all song information of Jacky Cheung can be retrieved and returned by album classification. Another example is that the front desk wants to query all songs whose name is Qi Qin, and the song names contain the word rain (that is, fuzzy matching is required), then the SQL statement generated by the background is: select * from music where singer ='Qi Qin' and mp3name Like '%rain%' order by id asc will return winter rain, sun rain, ruthless rain, ruthless you, etc. As long as you use appropriate techniques and flexible SQL statements, you can make the most of your topic search.
Music download function
----Provide music download function, which is also a basic function of music server, especially for remote users, who can enjoy their favorite songs only after downloading them.
There are generally two ways to provide downloading, one is to download directly through HTTP and browser, the other is to open the music library into an Ftp directory and download through ftp protocol. In this example, the former method is used, and the number of downloads is tracked and recorded in the database. Some sites also compress and encrypt songs as needed and provide passwords to official users, which is also a good idea. The procedure in this example is as follows:
<%
'##### Get the song identification 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 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
settset=nothing
settdb=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 build a basic music server. Of course, a complete music server can also include singer information, fan forums, chat rooms, voting stations, entertainment news networks and other functions, all of which can be implemented one by one using ASP. This article is limited by space and will not be discussed in detail. As long as the front-end page adopts a unique style design and perfect JavaScript program control, and the back-end programming uses flexible SQL statements and powerful ASP components, coupled with a well-planned Web database and rich creativity, a perfect music server can be built. Friends who are interested may wish to give it a try, you will create a miracle!