社区
Web 开发
帖子详情
如何实现点击一按钮就能播放歌曲?
untitled12
2003-10-01 08:54:27
请教
...全文
383
3
打赏
收藏
如何实现点击一按钮就能播放歌曲?
请教
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
luo525zheng
2003-10-01
打赏
举报
回复
<%--
Program Name: play.jsp
Author: 罗政
Purpose: 播放歌曲,本文件如移植到另外的服务器时须注意URL路径是否与服务器路径相符
Copyright 2002, developer_luozheng
--%>
<%--<%@ include file="data.jsp"%>--%>
<%--
Program Name: data.jsp
Author: 罗政
Purpose: 进行与数据库的连结,在其它要与数据库连接的页面中用include包含这个文件
Copyright 2002, developer_luozheng
--%>
<%@ page language="java" import="java.io.*,java.sql.*"%>
<%
//数据库连结对象
java.sql.Connection Conn;
//语句对象
java.sql.Statement Stmt;
//结果集对象
java.sql.ResultSet Rst;
//加载数据库驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
Conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","luozheng","luozheng");
Stmt=Conn.createStatement();
%>
<%@page contentType="text/html;charset=gb2312"%>
<%
//获得专辑id或歌曲id
String album_id=request.getParameter("album_id");
String song_id=request.getParameter("song_id");
//检查是否需要循环播放
String tag=request.getParameter("tag");
//避免产生NullPointerException异常
if(tag==null)
tag="";
//产生一个1到10的随机数
int I=(int)(Math.random()*10)+1;
if(album_id!=null)
{
//生成一个随机的m3u文件
String file_path="E:\\SKY-LUO\\sky-luo\\defaultroot\\musics\\M3U\\temp"+I+".m3u";
File m3u=new File(file_path);
if(!(m3u.exists()))
{
try{
//建军立m3u文件
m3u.createNewFile();
}
catch(IOException e)
{
out.println(e);
}
}
FileWriter result_m3u=new FileWriter(file_path);
PrintWriter new_m3u=new PrintWriter(result_m3u);
//更新点击数
Stmt.executeUpdate("update music_info set hits=hits+1 where album_id="+album_id);
//读取专辑歌曲信息
Rst=Stmt.executeQuery("select music_album.singer,music_album.album_name,music_info.filename from music_album,music_info where music_album.album_id=music_info.album_id and music_info.album_id="+album_id);
while(Rst.next())
{
String singer=Rst.getString("singer");
String album_name=Rst.getString("album_name");
String file_name=Rst.getString("filename");
//MP3文件的URL路径
String url="http://localhost:8080/musics/MP3/"+singer+"/"+album_name+"/"+file_name;
//写入URL到M3U文件中
new_m3u.println(url);
}
result_m3u.close();
}
else if(song_id!=null)
{
//更新点击数
Stmt.executeUpdate("update music_info set hits=hits+1 where music_id="+song_id);
//读取单个歌曲信息
Rst=Stmt.executeQuery("select music_album.singer,music_album.album_name,music_info.filename from music_album,music_info where music_album.album_id=music_info.album_id and music_info.music_id="+song_id);
Rst.next() ;
String singer=Rst.getString("singer");
String album_name=Rst.getString("album_name");
String file_name=Rst.getString("filename");
//MP3文件的URL路径
String url="http://localhost:8080/musics/MP3/"+singer+"/"+album_name+"/"+file_name;
//生成一个随机m3u文件
String file_path="E:\\SKY-LUO\\sky-luo\\defaultroot\\musics\\M3U\\temp"+I+".m3u";
File m3u=new File(file_path);
if(!(m3u.exists()))
{
try{
//建军立m3u文件
m3u.createNewFile();
}
catch(IOException e)
{
out.println(e);
}
}
FileWriter result_m3u=new FileWriter(file_path);
PrintWriter new_m3u=new PrintWriter(result_m3u);
//写入URL到M3U文件中
if(tag.equals("loop"))
{
for(int i=0;i<30;i++)
new_m3u.println(url);
}
else
{
new_m3u.println(url);
}
result_m3u.close();
}
response.sendRedirect("http://localhost:8080/musics/M3U/temp"+I+".m3u");
%>
<%--
Program Name: play_order.jsp
Author: 罗政
Purpose: 播放点播单歌曲,本文件如移植到另外的服务器时须注意URL路径是否与服务器路径相符
Copyright 2002, developer_luozheng
--%>
<%--<%@ include file="data.jsp"%>--%>
<%--
Program Name: data.jsp
Author: 罗政
Purpose: 进行与数据库的连结,在其它要与数据库连接的页面中用include包含这个文件
Copyright 2002, developer_luozheng
--%>
<%@ page language="java" import="java.io.*,java.sql.*"%>
<%
//数据库连结对象
java.sql.Connection Conn;
//语句对象
java.sql.Statement Stmt;
//结果集对象
java.sql.ResultSet Rst;
//加载数据库驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
Conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","luozheng","luozheng");
Stmt=Conn.createStatement();
%>
<%@page contentType="text/html;charset=gb2312"%>
<%
//产生一个1到10的随机数
int I=(int)(Math.random()*10)+1;
//生成一个随机的m3u文件
String file_path="E:\\SKY-LUO\\sky-luo\\defaultroot\\musics\\M3U\\temp"+I+".m3u";
File m3u=new File(file_path);
if(!(m3u.exists()))
{
try{
//建军立m3u文件
m3u.createNewFile();
}
catch(IOException e)
{
out.println(e);
}
}
FileWriter result_m3u=new FileWriter(file_path);
PrintWriter new_m3u=new PrintWriter(result_m3u);
//从session中获得点播歌曲id号
Vector order_list=(Vector)session.getValue("order");
int II;
int song_num=order_list.size();
for(II=0;II<song_num;II++)
{
String song_id=(String)order_list.elementAt(II);
//从数据库获取点播单歌曲的信息
Stmt.executeUpdate("update music_info set hits=hits+1 where music_id="+song_id);
Rst=Stmt.executeQuery("select music_album.singer,music_album.album_name,music_info.filename from music_album,music_info where music_album.album_id=music_info.album_id and music_info.music_id="+song_id);
Rst.next() ;
String singer=Rst.getString("singer");
String album_name=Rst.getString("album_name");
String file_name=Rst.getString("filename");
//生成MP3的URL
String url="http://localhost:8080/musics/MP3/"+singer+"/"+album_name+"/"+file_name;
//写入URL到M3U文件中
new_m3u.println(url);
}
//关闭文件
new_m3u.close();
response.sendRedirect("http://localhost:8080/musics/M3U/temp"+I+".m3u");
%>
欢迎来Email:luo525zheng@yahoo.com.cn一起探讨jsp中的问题.
hbzyduwu
2003-10-01
打赏
举报
回复
rm格式的,好象单击后,就能自动连到本地的realplay软件,然后播放
untitled12
2003-10-01
打赏
举报
回复
up
js音乐播放器
月光FM 查看演示 http://lunax.info/fm/ 希望大家在修改代码时能给本站留一个链接,谢谢
生日快乐 送女友源代码 小惊喜
在异性好友过生日的时候,特别制作了这个,全屏都在下蛋糕的小程序,蛋糕下降的过程中伴随生日快乐歌曲,文字闪烁标示出主题,绝对值得,自己原创,现将源码分享给大家,希望大家喜欢。
音乐播放器(C++源代码)
基于C++的音乐播放器
实现
源代码。C++ 播放器 源代码
网页向女友告白和纪念日专用特效
网页向女友告白和纪念日专用特效 源码下载 来自于屌丝程序员的爱情表白程序,表白,是一个非常神圣的事情,怎么才能成功呢?屌丝不会什么浪漫,只能写一个程序来表达。
android音乐播放器源码
该项目除了完成常规音乐播放器的基本功能外还增加了滑动图片切歌,甩歌功能和桌面快捷方式的添加。
Web 开发
81,117
社区成员
341,740
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章