社区
Web 开发
帖子详情
如何实现点击一按钮就能播放歌曲?
untitled12
2003-10-01 08:54:27
请教
...全文
378
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音乐播放器
2. **事件监听**:利用JavaScript的事件监听机制,可以响应用户的操作,如
点击
播放
按钮
、拖动音量滑块等,
实现
相应的功能。 3. **DOM操作**:为了更新UI(如显示当前播放时间、总时间、播放状态等),开发者需要...
生日快乐 送女友源代码 小惊喜
例如,可能有一个隐藏
按钮
,当用户
点击
时,蛋糕开始下落,歌曲开始播放。 7. **响应式设计**:为了确保在不同设备上都能良好运行,项目可能采用了响应式设计,利用媒体查询(Media Queries)根据设备的特性调整布局...
音乐播放器(C++源代码)
例如,当用户
点击
“播放”
按钮
时,会触发一个事件,该事件由事件处理函数响应,执行相应的播放操作。此外,多线程技术可能用于分离用户界面更新和音频播放,确保播放过程流畅且不被UI操作阻塞。 为了调试和优化,...
网页向女友告白和纪念日专用特效
例如,当用户
点击
“我爱你”
按钮
时,网页可以播放一段预录制的语音或者弹出一串动人的文字。此外,JavaScript还可以配合AJAX(Asynchronous JavaScript and XML)技术,从服务器端获取数据,如动态加载照片、歌曲或...
android音乐播放器源码
1. **多媒体框架**:Android的多媒体框架是
实现
音乐播放的基础。主要使用`MediaPlayer`类,它是Android提供的一个系统级服务,用于播放音频和视频文件。`MediaPlayer`提供了播放、暂停、停止、 seekTo(跳转到指定...
Web 开发
81,122
社区成员
341,744
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章