音乐在线欣赏 ----在线欣赏是指客户端利用播放器播放服务器端的音乐文件。其原理是当客户端向服务器提交音乐选单后,服务器生成相应的.m3u文件,并将该文件通过Http协议下行至客户端;客户端将被激发调用相应的播放器执行该文件,从而实现了音乐在线欣赏功能。目前支持.m3u文件的播放器有lank>Winamp、lank>Realplayer G2、 Musicmatch等。当这些播放器软件被正确安装在客户端时,就可以自动播放.m3u文件。所以解决问题的关键在于后台如何生成.m3u文件并下行到客户端。以下利用ASP中内置的FileSystem组件给出一种解决方案,并给出相应程序。 <% dim choose,path,mydb,myset,SQL,fs,mp3 ‘##### 获得list.htm表单中选中的lank>歌曲项 对应的id号,并赋给字串变量choose ##### choose=“(" for i=3 to request.form.count choose=choose+request.form(i)+“," next choose=left(choose,len(choose)-1)+“)" ‘##### 判断choose变量,如果不包含任何id号, 说明list.htm中没有选中任何歌曲,终止程序##### if choose=“()" then response.redirect(“list.htm") response.end end if ‘#####设置文件路径,需要把temp目录的权限设为 对internet匿名用户具有read & write 权限 ##### path=“E:\inetpub\wwwroot\temp\" ‘##### 创建文件对象 ##### Set fs = CreateObject(“Scripting.FileSystemObject") Set mp3 = fs.CreateTextFile(path+“listen.m3u", True) ‘##### 创建数据库对象##### set mydb=server.createobject(“adodb.connection") mydb.open “music" ‘##### 检索数据库,获得歌曲信息 ##### SQL=“select mp3name,url from "&dbname& “where id in "&choose set myset=tdb.execute(SQL) do while not myset.eof ‘##### 生成点播歌曲文件列表 ##### mp3.Write(“http://"+myset(“url")+chr(10)) myset.movenext loop ‘##### 更新数据库中的当天点播次数和 总共点播次数 ##### SQL=“update music set click=click+1, this=this+1 where id in "&choose mydb.execute(SQL) ‘##### 取消对象 ##### set myset=nothing mydb.close set mydb=nothing mp3.close set mp3=nothing ‘##### 将该文件下载给用户##### response.redirect(“listen.m3u") response.end %>